|
|
|
|
|
by eesmith
3225 days ago
|
|
"asdf".encode("hex") Is there a tool which knows to translate this to: import binascii
binascii.b2a_hex(b"asdf")
Even worse, if the string isn't known to be a byte string or ASCII unicode string, it's something like: import binascii
binascii.b2a_hex(s.encode("ascii") if isinstance(s, str) else s)
|
|
The snippet I posted is a little different in that it runs on both Python 2 as well as 3, but the 2to3 tools choke on it.