How to use the 'hex' encoding in Python 3.2 or higher?
Yet another way using binascii.hexlify()
:
>>> import binascii
>>> binascii.hexlify(b'\x12\x34\x56\x78')
b'12345678'
You need to go via the codecs
module and the hex_codec
codec (or its hex
alias if available*):
codecs.encode(b'\x12', 'hex_codec')
* From the documentation: "Changed in version 3.4: Restoration of the aliases for the binary transforms".