Message292710
Minimalist proposal:
def hex(self, *, bytes_per_group=None, delimiter=" "):
"""B.hex() -> string of hex digits
B.hex(bytes_per_group=N) -> hex digits in groups separated by *delimeter*
Create a string of hexadecimal numbers from a bytes object::
>>> b'\xb9\x01\xef'.hex()
'b901ef'
>>> b'\xb9\x01\xef'.hex(bytes_per_group=1)
'b9 01 ef'
"""
Alternatively, the grouping could be by digit rather than by byte:
def hex(self, *, group_digits=None, delimiter=" "):
"""B.hex() -> string of hex digits
B.hex(group_digits=N) -> hex digits in groups separated by *delimeter*
Create a string of hexadecimal numbers from a bytes object::
>>> b'\xb9\x01\xef'.hex()
'b901ef'
>>> b'\xb9\x01\xef'.hex(group_digits=2)
'b9 01 ef'
"""
One potential advantage of the `group_digits` approach is that it could be fairly readily adapted to the hex/oct/bin builtins (although if we did that, it would make the lack of a "dec" builtin for decimal formatting a bit weird) |
|
Date |
User |
Action |
Args |
2017-05-02 02:10:59 | ncoghlan | set | recipients:
+ ncoghlan, barry, gregory.p.smith, belopolsky, vstinner, eric.smith, gotgenes, Arfrever, Christian H |
2017-05-02 02:10:58 | ncoghlan | set | messageid: <1493691058.82.0.329524453522.issue22385@psf.upfronthosting.co.za> |
2017-05-02 02:10:58 | ncoghlan | link | issue22385 messages |
2017-05-02 02:10:58 | ncoghlan | create | |
|