Convert PySerial to python 3.0

Chris Rebert clp2 at rebertia.com
Tue Feb 24 22:55:44 EST 2009


On Tue, Feb 24, 2009 at 7:46 PM, Seth <king.seth at gmail.com> wrote:
> I am just messing around trying to get pyserial to work with 3.0.
>
> I am stuck on this line:
>
> if type(port) in [type(''), type(u'')]
>
>
> how can I convert this to 3.0? I tried changing the u to a d that did
> not do anything.

Looks like it's doing the equivalent of the pre-3.0-ism
`isinstance(port, basestring)`, but in a roundabout way.
However, since basestring doesn't exist in 3.0, either:

if isinstance(port, str):

Or

if isinstance(port, bytes):

would be the appropriate replacement. Depends (obviously) on whether
'port' is supposed to be unicode or a byte sequence.
Without more context, I can't really say which is what you want.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list