[Python-3000] about bytes
Terry Reedy
tjreedy at udel.edu
Fri Jun 27 21:50:31 CEST 2008
> Only if you didn't know that b'' is an alternative to bytes(). The b''
> notation is so much more compact and so much more helpful that I
> really don't want to go back to it. We will somehow have to deal with
> this through education and documentation.
http://bugs.python.org/issue3220
Improve Bytes and Byte Array Methods doc
makes several suggestions. For the issue here, I suggested (at the
bottom) adding
"Just as a bytes objects can be constructed either with a literal or a
class constructor call, they could be represented on output either by a
literal or class constructor call. The literal was chosen as being
shorter, generally more useful, and consistent with how other classes
are displayed. Similarly, the display of bytearrays uses the
corresponding bytes literal. If you want to see the bytes of either
class as integers, use tuple.
>>> a, b = b'abc', bytes((1,2,3))
>>> a,b
(b'abc', b'\x01\x02\x03')
>>> tuple(a), tuple(b)
((97, 98, 99), (1, 2, 3))
>>> c = bytearray(a)
>>> c, tuple(c)
(bytearray(b'abc'), (97, 98, 99))
"
I am assuming that there is no .to_int method that I missed.
Terry Jan Reedy
More information about the Python-3000
mailing list