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 subprocess 杀掉全部派生的子进程方法
Jan 16 Python
python常用知识梳理(必看篇)
Mar 23 Python
基于python指定包的安装路径方法
Oct 27 Python
pyqt5对用qt designer设计的窗体实现弹出子窗口的示例
Jun 19 Python
python实现的读取网页并分词功能示例
Oct 29 Python
wxpython绘制音频效果
Nov 18 Python
Pytorch十九种损失函数的使用详解
Apr 29 Python
Python3.9 beta2版本发布了,看看这7个新的PEP都是什么
Jun 10 Python
浅谈keras通过model.fit_generator训练模型(节省内存)
Jun 17 Python
解决运行django程序出错问题 'str'object has no attribute'_meta'
Jul 15 Python
Python使用Selenium模拟浏览器自动操作功能
Sep 08 Python
selenium判断元素是否存在的两种方法小结
Dec 07 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实现的自定义图像居中裁剪函数示例【测试可用】
2017/08/11 PHP
两种简单实现菜单高亮显示的JS类代码
2010/06/27 Javascript
javascript利用初始化数据装配模版的实现代码
2010/11/17 Javascript
基于json的jquery地区联动效果代码
2011/07/06 Javascript
JavaScript实现统计文本框Textarea字数增强用户体验
2012/12/21 Javascript
jquery图片放大功能简单实现
2013/08/01 Javascript
jQuery Animation实现CSS3动画示例介绍
2013/08/14 Javascript
JS delegate与live浅析
2013/12/21 Javascript
用JavaScript实现类似于ListBox功能示例代码
2014/03/09 Javascript
JavaScript实现更改网页背景与字体颜色的方法
2015/02/02 Javascript
JQuery插入DOM节点的方法
2015/06/11 Javascript
javascript+HTML5的Canvas实现Lab单车动画效果
2015/08/07 Javascript
基于BootstrapValidator的Form表单验证(24)
2016/12/12 Javascript
JavaScript中offsetWidth的bug及解决方法
2017/05/17 Javascript
深究AngularJS——ng-checked(回写:带真实案例代码)
2017/06/13 Javascript
Vuex利用state保存新闻数据实例
2017/06/28 Javascript
EasyUI的DataGrid每行数据添加操作按钮的实现代码
2017/08/22 Javascript
实现jquery放大镜的两种方法
2018/02/22 jQuery
Python之PyUnit单元测试实例
2014/10/11 Python
Python3 实现串口两进程同时读写
2019/06/12 Python
python 实现查询Neo4j多节点的多层关系
2019/12/23 Python
css3加js做一个简单的3D行星运转效果实例代码
2017/01/18 HTML / CSS
css3实现简单的白云飘动背景特效
2020/10/28 HTML / CSS
总经理职责
2013/12/22 职场文书
《蓝色的树叶》教学反思
2014/02/24 职场文书
《大作家的小老师》教学反思
2014/04/16 职场文书
应届大专生求职信
2014/06/26 职场文书
2014年绩效考核工作总结
2014/12/11 职场文书
社区植树节活动总结
2015/02/06 职场文书
2015年汽车销售工作总结
2015/04/07 职场文书
向雷锋同志学习倡议书
2015/04/27 职场文书
入党介绍人意见2015
2015/06/01 职场文书
详解JVM系列之内存模型
2021/06/10 Javascript
ElementUI实现el-form表单重置功能按钮
2021/07/21 Javascript
Spring中的使用@Async异步调用方法
2021/11/01 Java/Android
什么是clearfix (一文搞清楚css清除浮动clearfix)
2023/05/21 HTML / CSS