Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x

Christian Heimes lists at cheimes.de
Fri Jan 16 20:10:42 EST 2009


Giampaolo Rodola' schrieb:
> Now. The basic difference is that socket.recv() returns a bytes object
> instead of a string object and that's the thing which confuses me
> mainly.
> My question is: is there a way to convert that bytes object into
> exactly *the same thing* returned by socket.recv() in Python 2.x (a
> string)?

Python 3.0's bytes type is almost the same type as Python 2.x's str
type. During the development of Python 3.0 the old str type was modified
and renamed to bytes. The old unicode type is now known as str.

2.x     ->  3.0
-----------------
str     ->  bytes
unicode ->  str
""      ->  b""
u""     ->  ""

HTH

Christian




More information about the Python-list mailing list