python encode和decode的妙用


Posted in Python onSeptember 02, 2009

>>> "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 python 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 python 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 python 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
Python 相关文章推荐
Python 的内置字符串方法小结
Mar 15 Python
Python基于Socket实现的简单聊天程序示例
Aug 05 Python
python中numpy.zeros(np.zeros)的使用方法
Nov 07 Python
Python使用matplotlib绘制正弦和余弦曲线的方法示例
Jan 06 Python
python实现数独游戏 java简单实现数独游戏
Mar 30 Python
python如何使用unittest测试接口
Apr 04 Python
python DataFrame 取差集实例
Jan 30 Python
Python多线程同步---文件读写控制方法
Feb 12 Python
对python中的os.getpid()和os.fork()函数详解
Aug 08 Python
PyTorch中Tensor的拼接与拆分的实现
Aug 18 Python
Spring Boot中使用IntelliJ IDEA插件EasyCode一键生成代码详细方法
Mar 20 Python
Python新手如何理解循环加载模块
May 29 Python
python 简易计算器程序,代码就几行
Aug 29 #Python
python 提取文件的小程序
Jul 29 #Python
Python 文件重命名工具代码
Jul 26 #Python
python 生成目录树及显示文件大小的代码
Jul 23 #Python
python 域名分析工具实现代码
Jul 15 #Python
python 自动提交和抓取网页
Jul 13 #Python
python self,cls,decorator的理解
Jul 13 #Python
You might like
php除数取整示例
2014/04/24 PHP
php数组去除空值函数分享
2015/02/02 PHP
使用prototype.js进行异步操作
2007/02/07 Javascript
非常棒的10款jQuery 幻灯片插件
2011/06/14 Javascript
js简单实现HTML标签Select联动带跳转
2013/10/23 Javascript
DOM节点的替换或修改函数replaceChild()用法实例
2015/01/12 Javascript
jQuery实现可拖拽的许愿墙效果【附demo源码下载】
2016/09/14 Javascript
ionic由于使用了header和subheader导致被遮挡的问题的两种解决方法
2016/09/22 Javascript
json定义及jquery操作json的方法
2016/10/03 Javascript
JS实现间歇滚动的运动效果实例
2016/12/22 Javascript
JavaScript正则替换HTML标签功能示例
2017/03/02 Javascript
Angular4实现鼠标悬停3d倾斜效果
2017/10/25 Javascript
基于 D3.js 绘制动态进度条的实例详解
2018/02/26 Javascript
JavaScript私有变量实例详解
2019/01/24 Javascript
JS添加或删除HTML dom元素的方法实例分析
2019/03/05 Javascript
mpvue 项目初始化及实现授权登录的实现方法
2020/07/20 Javascript
用Python进行基础的函数式编程的教程
2015/03/31 Python
python实现一次创建多级目录的方法
2015/05/15 Python
详解Python的Django框架中manage命令的使用与扩展
2016/04/11 Python
Python构建网页爬虫原理分析
2017/12/19 Python
Django model 中设置联合约束和联合索引的方法
2019/08/06 Python
Python imutils 填充图片周边为黑色的实现
2020/01/19 Python
浅谈ROC曲线的最佳阈值如何选取
2020/02/28 Python
Python函数参数分类原理详解
2020/05/28 Python
Python 常用日期处理 -- calendar 与 dateutil 模块的使用
2020/09/02 Python
HTML5 canvas基本绘图之图形组合
2016/06/27 HTML / CSS
Woods官网:加拿大最古老、最受尊敬的户外品牌之一
2020/09/12 全球购物
大学毕业通用个人的求职信
2013/12/08 职场文书
医院总经理职责
2013/12/26 职场文书
上课迟到检讨书300字
2014/10/15 职场文书
实习单位证明范例
2014/11/17 职场文书
店面出租协议书范本
2014/11/28 职场文书
婚礼男方父母答谢词
2015/09/29 职场文书
2019请假条的基本格式及范文!
2019/07/05 职场文书
Javascript使用integrity属性进行安全验证
2021/11/07 Javascript
nginx中proxy_pass各种用法详解
2021/11/07 Servers