Re: py3k: converting int to bytes

2011-02-26 Thread J. Gerlach
Am 26.02.2011 12:26, schrieb J. Gerlach: > Am 24.02.2011 17:19, schrieb s...@uce.gov: >> >> Is there a better way to convert int to bytes then going through strings: >> >> x=5 >> str(x).encode() >> >> >> Thanks. >> > >>> bytes([8]) > b'\x08' > seems more straight forward... ... but it gives

Re: py3k: converting int to bytes

2011-02-26 Thread J. Gerlach
Am 24.02.2011 17:19, schrieb s...@uce.gov: > > Is there a better way to convert int to bytes then going through strings: > > x=5 > str(x).encode() > > > Thanks. > >>> bytes([8]) b'\x08' seems more straight forward... -- http://mail.python.org/mailman/listinfo/python-list

Re: py3k: converting int to bytes

2011-02-24 Thread Terry Reedy
On 2/24/2011 9:25 PM, John Machin wrote: On Feb 25, 4:39 am, Terry Reedy wrote: Note: an as yet undocumented feature of bytes (at least in Py3) is that bytes(count) == bytes()*count == b'\x00'*count. Python 3.1.3 docs for bytes() say same constructor args as for bytearray(); this says about t

Re: py3k: converting int to bytes

2011-02-24 Thread John Machin
On Feb 25, 4:39 am, Terry Reedy wrote: > Note: an as yet undocumented feature of bytes (at least in Py3) is that > bytes(count) == bytes()*count == b'\x00'*count. Python 3.1.3 docs for bytes() say same constructor args as for bytearray(); this says about the source parameter: """If it is an integ

Re: py3k: converting int to bytes

2011-02-24 Thread Terry Reedy
On 2/24/2011 11:19 AM, s...@uce.gov wrote: Is there a better way to convert int to bytes then going through strings: x=5 str(x).encode() (This being Py3) If 0 <= x <= 9, bytes((ord('0')+n,)) will work. Otherwise, no. You would have to do the same thing str(int) does, which is to reverse the

py3k: converting int to bytes

2011-02-24 Thread spam
Is there a better way to convert int to bytes then going through strings: x=5 str(x).encode() Thanks. -- Yves. http://www.SollerS.ca/ http://blog.zioup.org/ -- http://mail.python.org/mailma