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传递参数方式小结
Apr 17 Python
进一步探究Python中的正则表达式
Apr 28 Python
Python OS模块常用函数说明
May 23 Python
Python通过matplotlib绘制动画简单实例
Dec 13 Python
pandas通过字典生成dataframe的方法步骤
Jul 23 Python
pytorch使用指定GPU训练的实例
Aug 19 Python
python函数修饰符@的使用方法解析
Sep 02 Python
TensorFlow命名空间和TensorBoard图节点实例
Jan 23 Python
python第三方库学习笔记
Feb 07 Python
python实现3D地图可视化
Mar 25 Python
尝试使用Python爬取城市租房信息
Apr 12 Python
python中的random模块和相关函数详解
Apr 22 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
农民C键的运用技巧
2020/03/04 星际争霸
PHP 异步执行方法,模拟多线程的应用分析
2013/06/03 PHP
解决laravel资源加载路径设置的问题
2019/10/14 PHP
jQuery Tools tab使用介绍
2012/07/14 Javascript
js实现文本框中输入文字页面中div层同步获取文本框内容的方法
2015/03/03 Javascript
JavaScript获取一个范围内日期的方法
2015/04/24 Javascript
AngularJS基础学习笔记之控制器
2015/05/10 Javascript
深入解析JavaScript的闭包机制
2015/10/20 Javascript
jQuery获取浏览器类型和版本号的方法
2016/07/05 Javascript
js实现移动端轮播图效果
2020/12/09 Javascript
layui实现table加载的示例代码
2018/08/14 Javascript
vue封装一个简单的div框选时间的组件的方法
2019/01/06 Javascript
JavaScript随机数的组合问题案例分析
2020/05/16 Javascript
Python标准库os.path包、glob包使用实例
2014/11/25 Python
Python中使用装饰器来优化尾递归的示例
2016/06/18 Python
浅谈Python 集合(set)类型的操作——并交差
2016/06/30 Python
详细分析python3的reduce函数
2017/12/05 Python
Python 2.7中文显示与处理方法
2018/07/16 Python
Django的Modelforms用法简介
2019/07/27 Python
python Opencv计算图像相似度过程解析
2019/12/03 Python
python实现监控阿里云账户余额功能
2019/12/16 Python
python实现用类读取文件数据并计算矩形面积
2020/01/18 Python
CSS3实现翘边的阴影效果的代码示例
2016/06/13 HTML / CSS
中国首家奢侈品O2O网购平台:第五大道奢侈品网
2017/12/14 全球购物
澳大利亚汽车零部件、音响及配件超市:Automotive Superstore
2018/06/19 全球购物
竞争上岗演讲稿
2014/01/05 职场文书
毕业证丢失证明
2014/01/15 职场文书
个人近期表现材料
2014/02/11 职场文书
机关党员公开承诺书
2014/08/30 职场文书
庆祝教师节演讲稿
2014/09/03 职场文书
开展党的群众路线教育实践活动总结报告
2014/10/31 职场文书
后备干部推荐材料
2014/12/24 职场文书
自主招生自荐信范文
2015/03/04 职场文书
消防宣传标语大全
2015/08/03 职场文书
python基于tkinter制作无损音乐下载工具
2021/03/29 Python
MySQL脏读,幻读和不可重复读
2022/05/11 MySQL