Author lemburg
Recipients Arfrever, BreamoreBoy, christian.heimes, eric.araujo, georg.brandl, gotgenes, hct, lemburg, mark.dickinson, martin.panter, ncoghlan, pitrou, rhettinger, serhiy.storchaka, terry.reedy, vstinner, wiggin15
Date 2014-09-11.07:42:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <54115262.5080803@egenix.com>
In-reply-to <1410390247.33.0.30641506895.issue9951@psf.upfronthosting.co.za>
Content
On 11.09.2014 01:04, Nick Coghlan wrote:
> 
> Nick Coghlan added the comment:
> 
> Just as a recap of at least some of the *current* ways to do a bytes -> hex conversion:
> 
>>>> import codecs
>>>> codecs.encode(b"abc", "hex")
> b'616263'
>>>> import binascii
>>>> binascii.hexlify(b"abc")
> b'616263'
>>>> import base64
>>>> base64.b16encode(b"abc")
> b'616263'
>>>> hex(int.from_bytes(b"abc", "big"))
> '0x616263'
>>>> hex(int.from_bytes(b"abc", "little"))
> '0x636261'
> 
> Thus, the underlying purpose of this proposal is to provide a single "more obvious way to do it". As per the recent discussion on python-ideas, the point where that is most useful is in debugging output.
> 
> However, rather than a new method on bytes/bytearray/memoryview for this, I instead suggest it would be appropriate to extend the default handling of the "x" and "X" format characters to accept arbitrary bytes-like objects. The processing of these characters would be as follows:
> 
> "x": display a-f as lowercase digits
> "X": display A-F as uppercase digits
> "#": includes 0x prefix
> ".precision": chunks output, placing a space after every <precision> bytes
> ",": uses a comma as the separator, rather than a space

Hmm, but those would then work for str.format() as well, right ?

Since "x" and "X" are already used to convert numbers to hex
representation, opening these up for bytes sounds like it could
easily mask TypeErrors for cases where you really want an integer
to be formatted as hex and not bytes.
History
Date User Action Args
2014-09-11 07:42:36lemburgsetrecipients: + lemburg, georg.brandl, rhettinger, terry.reedy, mark.dickinson, ncoghlan, pitrou, vstinner, gotgenes, christian.heimes, eric.araujo, Arfrever, BreamoreBoy, wiggin15, martin.panter, serhiy.storchaka, hct
2014-09-11 07:42:36lemburglinkissue9951 messages
2014-09-11 07:42:35lemburgcreate