>>>"hello".encode("hex")
"68656c6c6f"
相应的还可以
>>>"68656c6c6f".decode("hex")
"hello"
查了一下手册,还有这些codec可用
Codec
Aliases
Operandtype
Purpose
base64_codec
base64,base-64
bytestring
ConvertoperandtoMIMEbase64
bz2_codec
bz2
bytestring
Compresstheoperandusingbz2
hex_codec
hex
bytestring
Convertoperandtohexadecimalrepresentation,withtwodigitsperbyte
idna
Unicodestring
ImplementsRFC3490.Newinversion2.3.Seealsoencodings.idna
mbcs
dbcs
Unicodestring
Windowsonly:EncodeoperandaccordingtotheANSIcodepage(CP_ACP)
palmos
Unicodestring
EncodingofPalmOS3.5
punycode
Unicodestring
ImplementsRFC3492.Newinversion2.3.
quopri_codec
quopri,quoted-printable,quotedprintable
bytestring
ConvertoperandtoMIMEquotedprintable
raw_unicode_escape
Unicodestring
ProduceastringthatissuitableasrawUnicodeliteralinpythonsourcecode
rot_13
rot13
Unicodestring
ReturnstheCaesar-cypherencryptionoftheoperand
string_escape
bytestring
Produceastringthatissuitableasstringliteralinpythonsourcecode
undefined
any
Raiseanexceptionforallconversions.CanbeusedasthesystemencodingifnoautomaticcoercionbetweenbyteandUnicodestringsisdesired.
unicode_escape
Unicodestring
ProduceastringthatissuitableasUnicodeliteralinpythonsourcecode
unicode_internal
Unicodestring
Returntheinternalrepresentationoftheoperand
uu_codec
uu
bytestring
Converttheoperandusinguuencode
zlib_codec
zip,zlib
bytestring
Compresstheoperandusinggzip