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 30 Python
Python素数检测的方法
May 11 Python
Python的math模块中的常用数学函数整理
Feb 04 Python
python文件与目录操作实例详解
Feb 22 Python
Python实现将一个正整数分解质因数的方法分析
Dec 14 Python
解决Python print 输出文本显示 gbk 编码错误问题
Jul 13 Python
python 计算平均平方误差(MSE)的实例
Jun 29 Python
基于python二叉树的构造和打印例子
Aug 09 Python
Python实现使用dir获取类的方法列表
Dec 24 Python
python matlab库简单用法讲解
Dec 31 Python
python如何修改文件时间属性
Feb 05 Python
python实现ROA算子边缘检测算法
Apr 05 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下10件你也许并不了解的事情
2008/09/11 PHP
选择PHP作为网站开发语言的原因分享
2012/01/03 PHP
浅析PHP文件下载原理
2014/12/25 PHP
PHP中session跨子域的三种实现方法
2016/07/25 PHP
PHP实现网页内容html标签补全和过滤的方法小结【2种方法】
2017/04/27 PHP
php实现页面纯静态的实例代码
2017/06/21 PHP
Javascript的一种模块模式
2008/03/22 Javascript
根据一段代码浅谈Javascript闭包
2010/12/14 Javascript
JavaScript高级程序设计(第3版)学习笔记7 js函数(上)
2012/10/11 Javascript
onkeydown事件解决按回车键直接提交数据的需求
2013/04/11 Javascript
javascript实现焦点滚动图效果 具体方法
2013/06/24 Javascript
Javascript设置对象的ReadOnly属性(示例代码)
2013/12/25 Javascript
jquery中trigger()无法触发hover事件的解决方法
2015/05/07 Javascript
jQuery的事件委托实例分析
2015/07/15 Javascript
JS模拟实现方法重载示例
2016/08/03 Javascript
JS判断浏览器是否安装flash插件的简单方法
2016/09/13 Javascript
jQuery progressbar通过Ajax请求实现后台进度实时功能
2016/10/11 Javascript
js 函数式编程学习笔记
2017/03/25 Javascript
详解jQuery中的prop()使用方法
2020/01/05 jQuery
python ip正则式
2009/05/07 Python
Python中实例化class的执行顺序示例详解
2018/10/14 Python
python turtle 绘制太极图的实例
2019/12/18 Python
详解torch.Tensor的4种乘法
2020/09/03 Python
python实现录音功能(可随时停止录音)
2020/10/26 Python
基于python实现监听Rabbitmq系统日志代码示例
2020/11/28 Python
HTML5 Canvas 旋转风车绘制
2017/08/18 HTML / CSS
捷克领先的户外服装及配件市场零售商:ALPINE PRO
2018/01/09 全球购物
巴西本土电商平台:Americanas
2020/06/21 全球购物
七年级历史教学反思
2014/02/05 职场文书
销售总经理岗位职责
2014/03/15 职场文书
出国签证在职证明
2014/09/20 职场文书
2015年父亲节寄语
2015/03/23 职场文书
运动员加油词
2015/07/18 职场文书
《假如》教学反思
2016/02/17 职场文书
【海涛教你打DOTA】剑圣第一人称视角解说
2022/04/01 DOTA
解决IIS7下无法绑定https主机的问题
2022/04/29 Servers