pyserial ser.write('string') TypeError in OS X

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Oct 20 18:01:01 EDT 2009


En Tue, 20 Oct 2009 18:02:03 -0300, Rodrigo <rodrigososa at gmail.com>  
escribió:

> Maybe this is not a bug at all, but i have installed python2.5. 3.01
> and 3.1.1. In python 2.5 ser. write('this is a string') works just
> fine.
> On the other hand, with 3.01 and 3.1.1 (pyserial 2.5 rc1) when i do a
> ser.write('this is a string') i get the following error"
>
> TypeError: expected <class 'bytes'> or bytearray, got <class 'str'>

Try with ser.write(b'this is a string')

Python 3.0 introduced many changes, one of them is to work with unicode by  
default. "abc" used to be a string (of bytes) in 2.x, and u"abc" unicode  
text. With Python 3.x, "abc" is unicode (spelled just `str` now) and  
b"abc" denotes the `bytes` type (the old str). bytearray is a mutable  
variant of the bytes type.

Read the "What's new" document for the 3.0 release:  
http://www.python.org/doc/3.0.1/whatsnew/

-- 
Gabriel Genellina




More information about the Python-list mailing list