GithubHelp home page GithubHelp logo

Comments (11)

the-raspberry-pi-guy avatar the-raspberry-pi-guy commented on June 3, 2024 2

This repository and tutorial is 6 years old @Kyuchumimo, and Python 2.7 support was the norm, especially for the other libraries this is built upon. If you would like to write and support a Python 3 setup then we would be more than happy to incorporate those changes into the repo, as long as it maintains full backwards-compatibility.

from lcd.

cgomesu avatar cgomesu commented on June 3, 2024

from lcd.

Kyuchumimo avatar Kyuchumimo commented on June 3, 2024

what's your python version? will take a look at it tomorrow.

Python 3.7.3, using Thonny IDE

from lcd.

cgomesu avatar cgomesu commented on June 3, 2024

Python 3.7.3

the driver was written for (and tested with) Python 2.7, as in the original (Youtube) tutorial and scripts. it may work with Python 3.x but in this particular case, it will raise an error because Python 3 makes a distinction between bytes and strings, whereas Python 2 does not.

This should fix the problem:

62 ... try:
63 ...     self.addr = int('0x{}'.format(
64 ...                       findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER), encoding='utf8']))[0]), base=16) \
65 ...                       if exists('/usr/sbin/i2cdetect') else addr_default

the use of encoding='utf8' in check_output is a good one for Python 3 but it should be outside the square brackets:

check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)], encoding='utf8')

I'd be happy to push such changes but the problem now is that encoding='utf8' is not supported in the Python 2 version of check_output.

can you think of an alternative that is compatible with both Python 2 and 3?

from lcd.

Kyuchumimo avatar Kyuchumimo commented on June 3, 2024

Sorry to put the encoding inside the brackets, it was a typo.

I can think of a solution, but that will be in a few hours, since I am not where I have my Raspberry Pi.
It occurs to me to use a separate function that changes the encoding.

from lcd.

Kyuchumimo avatar Kyuchumimo commented on June 3, 2024

Why would you still use python 2.7? Python 2 is deprecated. The latest version to date is Python 3.10

from lcd.

the-raspberry-pi-guy avatar the-raspberry-pi-guy commented on June 3, 2024

Are we still considering this a bug if this is a Python 3 compatibility issue @cgomesu ? Best to close this issue, or should we leave it open to clearly sign post?

from lcd.

Kyuchumimo avatar Kyuchumimo commented on June 3, 2024

It has more to do with compatibility than a bug

from lcd.

Kyuchumimo avatar Kyuchumimo commented on June 3, 2024

Done, this should fix the problem.
Works in both Python 2.7 and Python 3.7.3:

addr = int('0x{}'.format(
       findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]), base=16)

from lcd.

cgomesu avatar cgomesu commented on June 3, 2024

Are we still considering this a bug if this is a Python 3 compatibility issue @cgomesu ?

It has more to do with compatibility than a bug

I agree with you both. I added the bug label for quick reference because we do not have custom labels in this repo. I'll take care of that.

Best to close this issue, or should we leave it open to clearly sign post?

Let's wait for a fix from @Kyuchumimo. (See below.)

Done, this should fix the problem.
Works in both Python 2.7 and Python 3.7.3:

addr = int('0x{}'.format(
      findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]), base=16)

Thanks, @Kyuchumimo. I'll test the implementation when I get back home tomorrow. In the meantime, could you please submit a PR including only this change and linking to this issue?

from lcd.

cgomesu avatar cgomesu commented on June 3, 2024
check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]).decode())[0]

this change is compatible with both Python3 (3.7.3) and Python2 (2.7.16). tested on the following host:

Operating System: Raspbian GNU/Linux 10 (buster)
Kernel: Linux 5.10.63-v7+
Architecture: arm

waiting until the end of the week for @Kyuchumimo to submit a PR to the the-raspberry-pi-guy:master branch. otherwise, I'll submit one on my own, credit them in the commit message, and close this issue (#33) upon merge. please let me know about any objections until then.

from lcd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.