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性能优化的20条建议
Oct 25 Python
Using Django with GAE Python 后台抓取多个网站的页面全文
Feb 17 Python
python发送邮件功能实现代码
Jul 15 Python
一个基于flask的web应用诞生(1)
Apr 11 Python
Python实现删除时保留特定文件夹和文件的示例
Apr 27 Python
PyQt5固定窗口大小的方法
Jun 18 Python
基于Python实现大文件分割和命名脚本过程解析
Sep 29 Python
基于Python批量生成指定尺寸缩略图代码实例
Nov 20 Python
Python文件读写w+和r+区别解析
Mar 26 Python
OpenCV 表盘指针自动读数的示例代码
Apr 10 Python
python文件操作seek()偏移量,读取指正到指定位置操作
Jul 05 Python
Python判断变量是否是None写法代码实例
Oct 09 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中for循环语句的几种变型
2006/11/26 PHP
第4章 数据处理-php字符串的处理-郑阿奇(续)
2011/07/04 PHP
thinkphp框架无限级栏目的排序功能实现方法示例
2020/03/29 PHP
理解Javascript_06_理解对象的创建过程
2010/10/15 Javascript
jQuery.buildFragment使用方法及思路分析
2013/01/07 Javascript
NodeJS学习笔记之网络编程
2014/08/03 NodeJs
javascript 实现map集合
2015/04/03 Javascript
JavaScript使用Prototype实现面向对象的方法
2015/04/14 Javascript
详解vuejs之v-for列表渲染
2017/06/22 Javascript
JavaScript闭包_动力节点Java学院整理
2017/06/27 Javascript
SpringMVC简单整合Angular2的示例
2017/07/31 Javascript
jQuery DOM节点的遍历方法小结
2017/08/15 jQuery
如何抽象一个Vue公共组件
2017/10/17 Javascript
基于Proxy的小程序状态管理实现
2019/06/14 Javascript
JS中数据结构与算法---排序算法(Sort Algorithm)实例详解
2019/06/17 Javascript
微信小程序实现下滑到底部自动翻页功能
2020/03/07 Javascript
Layui弹框中数据表格中可双击选择一条数据的实现
2020/05/06 Javascript
解决vuecli3中img src 的引入问题
2020/08/04 Javascript
vant 解决tab切换插件标题样式自定义的问题
2020/11/13 Javascript
微信小程序学习之自定义滚动弹窗
2020/12/20 Javascript
Selenium控制浏览器常见操作示例
2018/08/13 Python
Django框架的中的setting.py文件说明详解
2018/10/15 Python
在Pycharm terminal中字体大小设置的方法
2019/01/16 Python
如何基于Python创建目录文件夹
2019/12/31 Python
使用AJAX和Django获取数据的方法实例
2020/10/25 Python
Ratchet 模态框的实现
2020/08/19 HTML / CSS
廉洁使者实施方案
2014/03/29 职场文书
计算机网络及管理学专业求职信
2014/06/05 职场文书
员工激励培训演讲稿
2014/09/16 职场文书
乡镇党建工作汇报材料
2014/10/27 职场文书
2014年公路养护工作总结
2014/12/04 职场文书
天下第一关导游词
2015/02/06 职场文书
交心谈心活动总结
2015/05/11 职场文书
PHP策略模式写法
2021/04/01 PHP
MySQL Router实现MySQL的读写分离的方法
2021/05/27 MySQL
2022微信温控新功能上线
2022/05/09 数码科技