L
Laszlo Nagy
We can convert from hex str to bytes with bytes.fromhex class method:
But we cannot convert from hex binary:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not bytes
We don't have bytes_instance.tohex() instance method.
But we have binascii.hexlify. But binascii.hexlify does not return an
str. It returns a bytes instance instead.
b'ff'
Its reverse function binascii.unhexlify can be used on str and bytes too:
b'\xff'
Questions:
* if we have bytes.fromhex() then why don't we have bytes_instance.tohex() ?
* if the purpose of binascii.unhexlify and bytes.fromhex is the same,
then why allow binary arguments for the former, and not for the later?
* in this case, should there be "one obvious way to do it" or not?
But we cannot convert from hex binary:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not bytes
We don't have bytes_instance.tohex() instance method.
But we have binascii.hexlify. But binascii.hexlify does not return an
str. It returns a bytes instance instead.
b'ff'
Its reverse function binascii.unhexlify can be used on str and bytes too:
b'\xff'
Questions:
* if we have bytes.fromhex() then why don't we have bytes_instance.tohex() ?
* if the purpose of binascii.unhexlify and bytes.fromhex is the same,
then why allow binary arguments for the former, and not for the later?
* in this case, should there be "one obvious way to do it" or not?