On Tue, Nov 21, 2017 at 6:37 AM, Kirill Balunov kirillbalunov@gmail.com wrote:
Currently, __repr__ and __str__ representation of bytes is the same. Perhaps it is worth making them different, this will make it easier to visually perceive them as a container of integers from 0 to 255, instead of a mixture of printable and non-printable ascii characters. It is proposed:
a) __str__ - leave unchanged b) __repr__ - represent as sequence of escaped hex
a = bytes([42,43,44,45,46]) a # Current
b'*+-./'
a # Proposed
b'\x2a\x2b\x2d\x2e\x2f'
supposedly __repr__ is supposed to give an eval-able version -- which your proposal is. But the way you did your example indicates that:
bytes((42, 43, 44, 45, 46))
would be an even better __repr__, if the goal is to make it clear and easy that it is a "container of integers from 0 to 255"
I've been programming since quite some time ago, and hex has NEVER come naturally to me :-)
But backward compatibility and all that :-(
-CHB