Menu

#35 Python 3 compatibility

v2.7
closed-rejected
5
2015-08-05
2014-08-25
No

I found that using 2to3 is not enough for Pyserial works properly using python3 [#161]. I've found that write method in serialposix.py use d = to_bytes(data). That works for pyhton2 but not for python 3. I made this modification and now my application works fine.

original:

# Previous code ...
def write(self, data):
        """Output the given string over the serial port."""
        if not self._isOpen: raise portNotOpenError

        d = to_bytes(data)

Modified:

# Previous code ...
def write(self, data):
        """Output the given string over the serial port."""
        if not self._isOpen: raise portNotOpenError

        if sys.version_info < (3,0):
            d = to_bytes(data)
        else:
            d = bytes(data,'ISO-8859-1')

Related

Bugs: #161

Discussion

  • Chris Liechti

    Chris Liechti - 2015-08-05

    pyserial expects bytes. any sort of encoding should be handler in the users code, not within the library.

     
  • Chris Liechti

    Chris Liechti - 2015-08-05
    • status: open --> closed-rejected
    • assigned_to: Chris Liechti
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.