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批量修改文件后缀的方法
Jan 26 Python
Python通过select实现异步IO的方法
Jun 04 Python
Python实现识别图片内容的方法分析
Jul 11 Python
Python操作json的方法实例分析
Dec 06 Python
python3 property装饰器实现原理与用法示例
May 15 Python
python简单鼠标自动点击某区域的实例
Jun 25 Python
python装饰器原理与用法深入详解
Dec 19 Python
Python处理mysql特殊字符的问题
Mar 02 Python
Python如何使用bokeh包和geojson数据绘制地图
Mar 21 Python
Pytorch 使用opnecv读入图像由HWC转为BCHW格式方式
Jun 02 Python
OpenCV读取与写入图片的实现
Oct 13 Python
jupyter notebook指定启动目录的方法
Mar 02 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
CodeIgniter错误mysql_connect(): No such file or directory解决方法
2014/09/06 PHP
PHP中调用SVN命令更新网站方法
2015/01/07 PHP
十个PHP高级应用技巧果断收藏
2015/09/25 PHP
jQuery 全选/反选以及单击行改变背景色实例
2013/07/02 Javascript
加随机数引入脚本不让浏览器读取缓存
2014/09/04 Javascript
jQuery实现仿淘宝带有指示条的图片转动切换效果完整实例
2015/03/04 Javascript
如何实现chrome浏览器关闭页面时弹出“确定要离开此面吗?”
2015/03/05 Javascript
jQuery实现的左右移动焦点图效果
2016/01/14 Javascript
JavaScript几种数组去掉重复值的方法推荐
2016/04/12 Javascript
bootstrap laydate日期组件使用详解
2017/01/04 Javascript
实例详解display:none与visible:hidden的区别
2017/03/30 Javascript
一份超级详细的Vue-cli3.0使用教程【推荐】
2018/11/15 Javascript
详解微信小程序调用支付接口支付
2019/04/28 Javascript
Webpack中loader打包各种文件的方法实例
2019/09/03 Javascript
LayUI数据接口返回实体封装的例子
2019/09/12 Javascript
Javascript异步编程async实现过程详解
2020/04/02 Javascript
vant 解决tab切换插件标题样式自定义的问题
2020/11/13 Javascript
vue 动态创建组件的两种方法
2020/12/31 Vue.js
python中pycurl库的用法实例
2014/09/30 Python
Python中asyncore异步模块的用法及实现httpclient的实例
2016/06/28 Python
Python实现压缩文件夹与解压缩zip文件的方法
2018/09/01 Python
python计算无向图节点度的实例代码
2019/11/22 Python
Python中如何将一个类方法变为多个方法
2019/12/30 Python
Python调用Windows命令打印文件
2020/02/07 Python
详解CSS3的perspective属性设置3D变换距离的方法
2016/05/23 HTML / CSS
Oakley西班牙官方商店:太阳眼镜和男女运动服
2019/04/26 全球购物
Roxy荷兰官方网站:冲浪、滑雪板、服装和配件
2019/10/22 全球购物
自我鉴定范文200字
2013/10/02 职场文书
大学生专科毕业生自我评价
2013/11/17 职场文书
英文自荐信格式
2013/11/28 职场文书
财务会计自荐信范文
2014/02/21 职场文书
2013年最新自荐信范文
2014/06/23 职场文书
新兵入伍心得体会
2014/09/04 职场文书
2014年全国爱牙日宣传活动方案
2014/09/21 职场文书
2014年节能工作总结
2014/12/18 职场文书
golang 在windows中设置环境变量的操作
2021/04/29 Golang