[issue16580] Add examples to int.to_bytes and int.from_bytes

2013-05-26 Thread Mark Dickinson
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, i

[issue16580] Add examples to int.to_bytes and int.from_bytes

2013-05-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I don't call it the examples. Here is the examples: >>> (1234).to_bytes(2, 'big') b'\x04\xd2' >>> (1234).to_bytes(2, 'little') b'\xd2\x04' >>> (-1234).to_bytes(2, 'big', signed=True) b'\xfb.' >>> int.from_bytes(b'\xde\xad\xbe\xef', 'big') 3735928559 >>> int.fr

[issue16580] Add examples to int.to_bytes and int.from_bytes

2013-05-25 Thread W. Owen Parry
W. Owen Parry added the comment: Patch adding examples + tests for equivalence. Comments appreciated. In particular, I'm not sure that the from_bytes example is simple enough to be useful: def from_bytes(bytes, byteorder, signed=False): if byteorder == 'little': little_ordered = li

[issue16580] Add examples to int.to_bytes and int.from_bytes

2013-01-13 Thread Ramchandra Apte
Changes by Ramchandra Apte : -- title: Add examples to int.to_bytres and int.from_bytes -> Add examples to int.to_bytes and int.from_bytes ___ Python tracker ___ ___