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 相关文章推荐
Django1.3添加app提示模块不存在的解决方法
Aug 26 Python
Python中的条件判断语句与循环语句用法小结
Mar 21 Python
python常用知识梳理(必看篇)
Mar 23 Python
python traceback捕获并打印异常的方法
Aug 31 Python
Python发送邮件测试报告操作实例详解
Dec 08 Python
Python 2/3下处理cjk编码的zip文件的方法
Apr 26 Python
Python 占位符的使用方法详解
Jul 10 Python
pytorch中交叉熵损失(nn.CrossEntropyLoss())的计算过程详解
Jan 02 Python
Python底层封装实现方法详解
Jan 22 Python
深入分析python 排序
Aug 24 Python
Python gevent协程切换实现详解
Sep 14 Python
python调用百度API实现人脸识别
Nov 17 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的autoload自动加载机制使用说明
2010/12/28 PHP
PHP 设计模式之观察者模式介绍
2012/02/22 PHP
Javascript中的var_dump函数实现代码
2009/09/07 Javascript
jquery.cvtooltip.js 基于jquery的气泡提示插件
2010/11/19 Javascript
Js实现当前点击a标签变色突出显示其他a标签回复原色
2013/11/27 Javascript
javascript实现点击后变换按钮显示文字的方法
2015/05/13 Javascript
JavaScript操作Cookie方法实例分析
2015/05/27 Javascript
获取阴历(农历)和当前日期的js代码
2016/02/15 Javascript
jQuery使用$.each遍历json数组的简单实现方法
2016/04/18 Javascript
JavaScript学习小结之被嫌弃的eval函数和with语句实例详解
2016/08/01 Javascript
详解获取jq ul第一个li定位的四种解决方案
2016/11/23 Javascript
谈谈Vue.js——vue-resource全攻略
2017/01/16 Javascript
jQuery插件jquery.kxbdmarquee.js实现无缝滚动效果
2017/02/15 Javascript
Vue.js 2.0 移动端拍照压缩图片上传预览功能
2017/03/06 Javascript
JavaScript使用链式方法封装jQuery中CSS()方法示例
2017/04/07 jQuery
Vue2.0用 watch 观察 prop 变化(不触发)
2017/09/08 Javascript
jQuery访问浏览器本地存储cookie、localStorage和sessionStorage的基本用法
2017/10/20 jQuery
Vue.js的模板语法详解
2020/02/16 Javascript
[00:12]DAC2018 Miracle-站上中单舞台,他能否再写奇迹?
2018/04/06 DOTA
python非递归全排列实现方法
2017/04/10 Python
Python中关于Sequence切片的下标问题详解
2017/06/15 Python
Python使用getpass库读取密码的示例
2017/10/10 Python
Python查找两个有序列表中位数的方法【基于归并算法】
2018/04/20 Python
python和shell获取文本内容的方法
2018/06/05 Python
python实现人民币大写转换
2018/06/20 Python
Python 使用类写装饰器的小技巧
2018/09/30 Python
Python爬虫将爬取的图片写入world文档的方法
2018/11/07 Python
使用pandas实现csv/excel sheet互相转换的方法
2018/12/10 Python
美国领先的医疗警报服务:Philips Lifeline
2018/03/12 全球购物
化学相关工作求职信
2013/10/02 职场文书
合同专员岗位职责
2013/12/18 职场文书
国家励志奖学金获奖感言
2014/01/09 职场文书
2014年父亲节活动方案
2014/03/06 职场文书
机关单位动员会主持词
2014/03/20 职场文书
祝福语集锦:给满月宝宝的祝福语
2019/11/20 职场文书
使用php的mail()函数实现发送邮件功能
2021/06/03 PHP