python encode和decode的妙用
程序员文章站
2022-05-25 18:43:21
>>> "hello".encode("hex") '68656c6c6f'
相应的还可以
>>> '68656c6c6f'.dec...
>>> "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 rfc 3490. 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 rfc 3492. 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 |
上一篇: SQL 根据汉字获取全拼的代码
下一篇: 浅谈内容收录与网站权重