[Python-ideas] bitwise operations on bytes

Eric Eisner ede at mit.edu
Tue Aug 11 00:38:51 CEST 2009

On Tue, Aug 11, 2009 at 02:16, Ron Adam<rrr at ronadam.com> wrote:
> The constructor for the int type already does base and string conversions,
> extending it to bytes seems like it would be natural.
>   int(bytes)            # just like int(string)
>   bytes = bytes(int)    # calls int.__to_bytes__() to do the actual work.

The constructor for bytes currently accepts a single int as an
argument, producing that many zero bytes. As far as I can tell this
behavior is undocumented, but I don't know if that can be changed

The first thing I did when I tried out the bytes type in 3.x was to
try to convert an int to a byte via the constructor, and the current
behavior surprised me.


More information about the Python-ideas mailing list