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 测试实现方法
Dec 24 Python
python读取Android permission文件
Nov 01 Python
python抓取网页时字符集转换问题处理方案分享
Jun 19 Python
python 读取文本文件的行数据,文件.splitlines()的方法
Jul 12 Python
详解django+django-celery+celery的整合实战
Mar 19 Python
python基于K-means聚类算法的图像分割
Oct 30 Python
DJango的创建和使用详解(默认数据库sqlite3)
Nov 18 Python
Python使用turtle库绘制小猪佩奇(实例代码)
Jan 16 Python
Tensorflow轻松实现XOR运算的方式
Feb 03 Python
Python爬取新型冠状病毒“谣言”新闻进行数据分析
Feb 16 Python
python中xlutils库用法浅析
Dec 29 Python
Matplotlib绘制混淆矩阵的实现
May 27 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检测图片木马多进制编程实践
2013/04/11 PHP
php实现查询百度google收录情况(示例代码)
2013/08/02 PHP
PHP获取文件夹内文件数的方法
2015/03/12 PHP
PHP的压缩函数实现:gzencode、gzdeflate和gzcompress的区别
2016/01/27 PHP
PHP基于curl post实现发送url及相关中文乱码问题解决方法
2017/11/25 PHP
浅析PHP类的反射来实现依赖注入过程
2018/02/06 PHP
php 广告点击统计代码(php+mysql)
2018/02/21 PHP
Laravel框架路由管理简单示例
2019/05/07 PHP
javascript改变position值实现菜单滚动至顶部后固定
2013/01/18 Javascript
jQuery中操控hidden、disable等无值属性的方法
2014/01/06 Javascript
showModalDialog模态对话框的使用详解以及浏览器兼容
2014/01/11 Javascript
js中用window.open()打开多个窗口的name问题
2014/03/13 Javascript
jQuery源码解读之addClass()方法分析
2015/02/20 Javascript
解决bootstrap中modal遇到Esc键无法关闭页面
2015/03/09 Javascript
jQuery简单实现两级下拉菜单效果代码
2015/09/15 Javascript
浅析jQuery Ajax请求参数和返回数据的处理
2016/02/24 Javascript
node.js cookie-parser之parser.js
2016/06/06 Javascript
浅谈JavaScript异步编程
2017/01/20 Javascript
Vue中的slot使用插槽分发内容的方法
2018/03/01 Javascript
基于Vue实现拖拽效果
2018/04/27 Javascript
js动态设置select下拉菜单的默认选中项实例
2018/08/21 Javascript
详解vantUI框架在vue项目中的应用踩坑
2018/12/06 Javascript
浅谈express.js框架中间件(middleware)
2019/04/07 Javascript
Python的GUI框架PySide的安装配置教程
2016/02/16 Python
python基于itchat实现微信群消息同步机器人
2017/02/27 Python
PyQt 实现使窗口中的元素跟随窗口大小的变化而变化
2019/06/18 Python
Python的几种主动结束程序方式
2019/11/22 Python
Python实现图像去噪方式(中值去噪和均值去噪)
2019/12/18 Python
Pyecharts地图显示不完成问题解决方案
2020/05/11 Python
在HTML5 canvas里用卷积核进行图像处理的方法
2018/05/02 HTML / CSS
Smashbox英国官网:美国知名彩妆品牌
2017/11/13 全球购物
中东最大的在线宠物店:Dubai Pet Food
2020/06/11 全球购物
为数据库创建索引都需要注意些什么
2012/07/17 面试题
Linux内核的同步机制是什么?主要有哪几种内核锁
2013/01/03 面试题
三严三实对照检查材料思想汇报
2014/09/28 职场文书
2016年春季开学典礼新闻稿
2015/11/25 职场文书