
Eric Eisner schrieb:
On Tue, Aug 11, 2009 at 02:16, Ron Adam<rrr@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 easily...
It is documented, see http://docs.python.org/py3k/library/functions#bytearray. Georg -- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.