Convert PySerial to python 3.0
grante at visi.com
Wed Feb 25 05:22:34 CET 2009
On 2009-02-25, Chris Rebert <clp2 at rebertia.com> wrote:
> 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):
> if isinstance(port, bytes):
> would be the appropriate replacement. Depends (obviously) on
> whether 'port' is supposed to be unicode or a byte sequence.
Port can either be an integer or a file/device name.
> Without more context, I can't really say which is what you
In the line of code in question, the conditional is inteded to
be true if "port" is someting that could be passed to the OS as
a file or device name.
More information about the Python-list