[Python-ideas] Direct byte<->int conversions (was Re: bitwise operations on bytes)

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Aug 11 03:08:57 CEST 2009

Nick Coghlan wrote:

> As far as bytearray goes, my original post did suggest that approach
> (i.e. class methods on the target types), but that then gets tedious as
> every new type that wants to support conversion from an integer needs to
> either go through one of the existing types or else have it's own C
> extension call the underlying C API directly.

I'd suggest that int.to_bytes should take an optional destination
parameter, and it should accept any object having a mutable
buffer interface.

That would keep all the int-related methods with the int class,
without restricting the source or destination to any particular


More information about the Python-ideas mailing list