Terry J. Reedy added the comment:

To answer Serhiy, the goal is to have a bytes method that represents bytes as 
bytes rather than as a mixture of bytes and encoded ascii characters. This 
would aid people who work with bytes that are not encoded ascii and that do not 
embed encoded ascii. It should not be necessary to import anything.  

>>> hex(int.from_bytes(b'abc', 'big'))
'0x616263'
is a bit baroque and produces a hex representation of an int, not of multiple 
bytes.

I think following the float precedent is a good idea.
>>> float.fromhex(1.5.hex())
1.5
>>> float.fromhex('0x1.8000000000000p+0').hex()
'0x1.8000000000000p+0'

The output of bytes.hex should be one that is accepted by bytes.fromhex, which 
is to say, hex 'digit' pairs. Spaces are optionally allowed between pairs. I 
would add a 'spaces' parameter, defaulting to False. to output spaces when set 
to true.  (Or possible reverse the default  -- what do potential users think?)

A possible altermative for the parameter could be form='' (default), form=' ' 
(add spaces), and form='x' to add '\x' prefixes.  I don't know that adding '\x' 
would be useful. The prefixes are not accepted by .fromhex.

----------
versions: +Python 3.5 -Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9951>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to