当前位置: 移动技术网 > IT编程>脚本编程>Python > python encode和decode的妙用

python encode和decode的妙用

2019年04月05日  | 移动技术网IT编程  | 我要评论

源码中国,龙水五金,东京食尸鬼re10

>>> "hello".encode("hex")
'68656c6c6f'

相应的还可以

>>> '68656c6c6f'.decode("hex")
'hello'

查了一下手册,还有这些codec可用

codec

aliases

operand type

purpose

base64_codec base64, base-64 byte string convert operand to mime base64
bz2_codec bz2 byte string compress the operand using bz2
hex_codec hex byte string convert operand to hexadecimal representation, with two digits per byte
idna   unicode string implements . new in version 2.3. see also encodings.idna
mbcs dbcs unicode string windows only: encode operand according to the ansi codepage (cp_acp)
palmos   unicode string encoding of palmos 3.5
punycode   unicode string implements . new in version 2.3.
quopri_codec quopri, quoted-printable, quotedprintable byte string convert operand to mime quoted printable
raw_unicode_escape   unicode string produce a string that is suitable as raw unicode literal in source code
rot_13 rot13 unicode string returns the caesar-cypher encryption of the operand
string_escape   byte string produce a string that is suitable as string literal in source code
undefined   any raise an exception for all conversions. can be used as the system encoding if no automatic coercion between byte and unicode strings is desired.
unicode_escape   unicode string produce a string that is suitable as unicode literal in source code
unicode_internal   unicode string return the internal representation of the operand
uu_codec uu byte string convert the operand using uuencode
zlib_codec zip, zlib byte string compress the operand using gzip

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网