Convert PySerial to python 3.0

Christian Heimes lists at cheimes.de
Wed Feb 25 10:16:11 EST 2009


Seth wrote:
> I tried all three ways you guys listed nothing seems to convert the
> string to bytes.
> 
> It may have to do with the makeDeviceName function, but I can't find
> where that is defined.
> 
> Any thoughts??
> 
> Here is the whole block of code:
> 
> if type(port) in (str, bytes):       #strings are taken directly
> Originally:     if type(port) in [type(''), type(u'')]
>                 self.portstr = port
>             else:
>                 self.portstr = self.makeDeviceName(port)

str and bytes are two totally unrelated things in Python 3.0. You can no
longer treat them equally like str and unicode in Python 2.x. Your could
should not work under Python 3.0 anyway. u'' is invalid in 3.x.

Also please don't use ugly type checks like type(something) == type('').
Starting with Python 2.2 you should use isinstance, for example
isinstance(number, (int, long)).

Christian




More information about the Python-list mailing list