首页 > 编程 > Python > 正文

python encode和decode的妙用

2020-02-23 04:44:43
字体:
来源:转载
供稿:网友

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

相应的还可以

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

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

Codec

Aliases

Operand type

Purpose

base64_codecbase64, base-64byte stringConvert operand to MIME base64
bz2_codecbz2byte stringCompress the operand using bz2
hex_codechexbyte stringConvert operand to hexadecimal representation, with two digits per byte
idna Unicode stringImplements RFC 3490. New in version 2.3. See also encodings.idna
mbcsdbcsUnicode stringWindows only: Encode operand according to the ANSI codepage (CP_ACP)
palmos Unicode stringEncoding of PalmOS 3.5
punycode Unicode stringImplements RFC 3492. New in version 2.3.
quopri_codecquopri, quoted-printable, quotedprintablebyte stringConvert operand to MIME quoted printable
raw_unicode_escape Unicode stringProduce a string that is suitable as raw Unicode literal in python source code
rot_13rot13Unicode stringReturns the Caesar-cypher encryption of the operand
string_escape byte stringProduce a string that is suitable as string literal in python source code
undefined anyRaise an exception for all conversions. Can be used as the system encoding if no automatic coercion between byte and Unicode strings is desired.
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表