Re: int.to_bytes() for a single byte

2018-11-07 Thread Thomas Jollans
On 07/11/2018 05:22, jlada...@itu.edu wrote: > On Tuesday, November 6, 2018 at 7:19:09 PM UTC-8, Terry Reedy wrote: >> On 11/6/2018 9:30 PM, j...y@it.u wrote: >> >>> b = i.to_bytes(1, "big") >>> >>> Is there another function which provides a more logical interface to this >>> straightforward task?

Re: int.to_bytes() for a single byte

2018-11-06 Thread jladasky
On Tuesday, November 6, 2018 at 7:19:09 PM UTC-8, Terry Reedy wrote: > On 11/6/2018 9:30 PM, j...y@it.u wrote: > > > b = i.to_bytes(1, "big") > > > >Is there another function which provides a more logical interface to this > >straightforward task? > > Yes > >>> 33 .to_bytes(1, 'big') > b'!' >

Re: int.to_bytes() for a single byte

2018-11-06 Thread Terry Reedy
On 11/6/2018 9:30 PM, jlada...@itu.edu wrote: b = i.to_bytes(1, "big") Is there another function which provides a more logical interface to this straightforward task? Yes >>> 33 .to_bytes(1, 'big') b'!' >>> bytes((33,)) b'!' See >>> bytes( # in IDLE or >>> help(bytes) -- Terry Jan Reedy

Re: int.to_bytes() for a single byte

2018-11-06 Thread bob gailer
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 fi

int.to_bytes() for a single byte

2018-11-06 Thread jladasky
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 byteorde