Message226703
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. |
|
Date |
User |
Action |
Args |
2014-09-10 17:58:54 | terry.reedy | set | recipients:
+ terry.reedy, georg.brandl, rhettinger, mark.dickinson, ncoghlan, pitrou, vstinner, gotgenes, christian.heimes, eric.araujo, Arfrever, wiggin15, martin.panter, serhiy.storchaka, hct |
2014-09-10 17:58:54 | terry.reedy | set | messageid: <1410371934.49.0.889669199689.issue9951@psf.upfronthosting.co.za> |
2014-09-10 17:58:54 | terry.reedy | link | issue9951 messages |
2014-09-10 17:58:54 | terry.reedy | create | |
|