Nov-22-2017, 01:13 PM
bytes objects really only exist in Python 3.x.
bytes added in Python 2.6 is an alias to the
that only exists to help writing portable code between Python 2 and 3.
The Doc for this 2.6:
bytes added in Python 2.6 is an alias to the
str
type,that only exists to help writing portable code between Python 2 and 3.
The Doc for this 2.6:
Quote:Python 2.6 adds bytes as a synonym for the str type, and it also supports the b'' notation.
The 2.6 str differs from 3.0’s bytes type in various ways; most notably, the constructor is completely different.
n 3.0, bytes([65, 66, 67]) is 3 elements long, containing the bytes representing ABC; in 2.6, bytes([65, 66, 67]) returns the 12-byte string representing the str() of the list.
The primary use of bytes in 2.6 will be to write tests of object type such as isinstance(x, bytes).
his will help the 2to3 converter, which can’t tell whether 2.x code intends strings to contain either characters or 8-bit bytes;
ou can now use either bytes or str to represent your intention exactly, and the resulting code will also be correct in Python 3.0.