Skip to content

Instantly share code, notes, and snippets.

@nuryslyrt
Created July 19, 2017 14:11
Show Gist options
  • Save nuryslyrt/64ce0950b2afd6c2035a5ea8d76b0e89 to your computer and use it in GitHub Desktop.
Save nuryslyrt/64ce0950b2afd6c2035a5ea8d76b0e89 to your computer and use it in GitHub Desktop.
In Python 3 you can't call encode() on 8-bit strings anymore, so the hex codec became pointless and was removed.
Although you theoretically could have a hex codec and use it like this:
>>> import codecs
>>> hexlify = codecs.getencoder('hex')
>>> hexlify(b'Blaah')[0]
b'426c616168'
Using binascii is easier and nicer:
>>> import binascii
>>> binascii.hexlify(b'Blaah')
b'426c616168'
Also the hex codec has been chucked in 3.x. I'm using binascii instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment