On 11/6/2018 9:30 PM, jlada...@itu.edu wrote:
I'm using Python 3.6.  I have a need to convert several small integers into 
single bytes.  As far as I can tell from reading through the Python docs, the 
correct way to accomplish this task is:

b = i.to_bytes(1, "big")

This seems to work, but I find it cumbersome.  I have to supply the byteorder argument to prevent a 
TypeError.  However, byte order doesn't matter if I'm only generating a single byte.  Whether I 
choose "big" or "little" I should get the same result.  Is there another 
function which provides a more logical interface to this straightforward task?
Take a look at the struct module.

Bob Gailer
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to