python encode和decode的妙用

时间:2021-01-08 01:34:20 

>>> "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.
unicode_escape Unicode stringProduce a string that is suitable as Unicode literal in python source code
unicode_internal Unicode stringReturn the internal representation of the operand
uu_codecuubyte stringConvert the operand using uuencode
zlib_codeczip, zlibbyte stringCompress the operand using gzip

标签:python,encode,decode
0
投稿

猜你喜欢

  • python 多线程应用介绍

    2023-07-13 08:04:04
  • 用js封装的时间设置器

    2013-08-04 23:28:46
  • Python正则表达式匹配HTML页面编码

    2023-07-29 06:50:36
  • 详解Python使用OpenCV如何确定一个对象的方向

    2022-04-06 04:16:42
  • 为SQL Server数据库传数组参数的变通办法

    2009-10-23 09:26:00
  • GoJs的文本绘图模板TextBlock使用实例

    2023-08-26 16:01:00
  • Python第三方库face_recognition在windows上的安装过程

    2023-07-27 02:51:29
  • Python实现方便使用的级联进度信息实例

    2021-04-22 12:31:18
  • 深入浅析Python 命令行模块 Click

    2022-12-13 19:41:40
  • Python Django view 两种return的实现方式

    2022-05-03 16:07:04
  • python3.6根据m3u8下载mp4视频

    2021-05-22 00:20:03
  • AJAX在GET中文的时候解决乱码的方法

    2007-11-04 13:04:00
  • 在Typescript中如何使用for...in详解

    2023-08-18 15:39:32
  • Flask 使用类组织配置详情

    2023-06-15 02:31:30
  • FckEditor配置手册中文教程详细说明

    2010-02-28 12:37:00
  • 细化解析:SQL Server 2005 数据库镜像

    2009-01-23 13:41:00
  • 如何用python反转图片,视频

    2023-08-27 08:18:21
  • 比较一下看看自己掌握了多少SQL快捷键

    2009-01-04 14:04:00
  • 有关Oracle数据库的备份情况

    2010-07-30 13:21:00
  • 解决pycharm中opencv-python导入cv2后无法自动补全的问题(不用作任何文件上的修改)

    2023-08-24 00:25:21
  • asp之家 网络编程 m.aspxhome.com