Mark Dickinson added the comment:
The `from_bytes` example code looks fine to me, except that I'd probably use
`enumerate` in the iteration; i.e.,
sum(b << 8*i for i, b in enumerate(little_ordered))
instead of
sum(little_ordered[i] << i*8 for i in range(len(little_ordered)))
Also, in:
if signed and little_ordered and (little_ordered[-1] & 0x80):
I wondered why you needed the `little_ordered` check. But I see that
`int.from_bytes(b'', 'little', signed=True)` produces `0`, which is a little
bit disappointing: I was expecting an exception. (A signed format should have
a sign bit, which is impossible if the length of the byte string is 0.)
The `to_bytes` example code is missing range checks for the input. It may be
clearer to simply state that in the docs, instead of modifying the example code
to add the range checks.
----------
nosy: +mark.dickinson
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16580>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com