[Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?] (original) (raw)

Adam Olsen rhamph at gmail.com
Wed Feb 15 12:08:46 CET 2006


On 2/15/06, Ron Adam <rrr at ronadam.com> wrote:

Greg Ewing wrote: > Ron Adam wrote: >> b = bytes(0L) -> bytes([0,0,0,0]) > > No, bytes(0L) --> TypeError because 0L doesn't implement > the iterator protocol or the buffer interface.

It wouldn't need it if it was a direct C memory copy. > I suppose long integers might be enhanced to support the > buffer interface in 3.0, but that doesn't seem like a good > idea, because the bytes you got that way would depend on > the internal representation of long integers. In particular, Since some longs will be of different length, yes a bytes(0L) could give differing results on different platforms, but it will always give the same result on the platform it is run on. I actually think this is a plus and not a problem. If you are using Python to implement a byte interface you need to know it is different, not have it hidden. bytesize = len(bytes(0L)) # find how long a long is

I believe you're confusing a C long with a Python long. A Python long is implemented as an array and has variable size.

In any case we already have the struct module:

import struct struct.calcsize('l') 4

-- Adam Olsen, aka Rhamphoryncus



More information about the Python-Dev mailing list