The bytes.hex() function is the inverse function of Bytes.fromhex().

But fromhex can process spaces (which is much more readable), while hex() provides no way to include spaces.

 

My proposal would be to add an optional delimiter, that allows to specify a string that will be inserted between the digit pairs of a byte:

 

def hex(self, delimiter=‘‘): …

 

This would allow to write:

 

assert b’abc‘.hex(‘ ‘) == ’61 62 63‘

 

Gesendet von Mail für Windows 10