Ned Deily added the comment: This is as expected. In Python 3, b'text' represents a bytes object. "Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation". Also, in the case of simple bytes objects, their str() representation is the same as their repr() representation. For many simple types, the repr() representation of an object allows you to recover the object by using eval().
>>> b'one' b'one' >>> type(b'one') <class 'bytes'> >>> str(b'one') "b'one'" >>> repr(b'one') "b'one'" >>> eval(repr(b'one')) b'one' >>> b'one'.decode('ascii') 'one' https://docs.python.org/3/library/stdtypes.html#str https://docs.python.org/3/library/functions.html#repr Python 2 (as of 2.6) accepts b'text' literals to make writing code compatible with both Py2 and Py3 easier. However, Py2 treats b'text' the same as 'text'. >>> b'one' 'one' >>> type(b'one') <type 'str'> >>> str(b'one') 'one' >>> b'one'.decode('ascii') u'one' https://docs.python.org/2/whatsnew/2.6.html#pep-3112-byte-literals ---------- nosy: +ned.deily resolution: -> not a bug stage: -> resolved status: open -> closed _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue21954> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com