This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Arfrever, christian.heimes, eric.araujo, georg.brandl, gotgenes, hct, mark.dickinson, martin.panter, ncoghlan, pitrou, rhettinger, serhiy.storchaka, terry.reedy, vstinner, wiggin15
Date 2014-09-10.17:58:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410371934.49.0.889669199689.issue9951@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-09-10 17:58:54terry.reedysetrecipients: + 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:54terry.reedysetmessageid: <1410371934.49.0.889669199689.issue9951@psf.upfronthosting.co.za>
2014-09-10 17:58:54terry.reedylinkissue9951 messages
2014-09-10 17:58:54terry.reedycreate