G
Guest
Is there a better way to convert int to bytes then going through strings:
x=5
str(x).encode()
Thanks.
x=5
str(x).encode()
Thanks.
Is there a better way to convert int to bytes then going through strings:
x=5
str(x).encode()
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
integer, the array will have that size and will be initialized with
null bytes"""
b'\x08'Is there a better way to convert int to bytes then going through strings:
x=5
str(x).encode()
Thanks.
bytes([8])
.... but it gives a different result. I should've tested beforeAm 24.02.2011 17:19, schrieb (e-mail address removed):b'\x08'Is there a better way to convert int to bytes then going through strings:
x=5
str(x).encode()
Thanks.
bytes([8])
seems more straight forward...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.