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中去空格函数的用法
Aug 21 Python
Python使用Flask框架获取当前查询参数的方法
Mar 21 Python
详解Python的迭代器、生成器以及相关的itertools包
Apr 02 Python
用Python实现一个简单的能够发送带附件的邮件程序的教程
Apr 08 Python
python学习笔记之列表(list)与元组(tuple)详解
Nov 23 Python
python批量替换页眉页脚实例代码
Jan 22 Python
python查找指定文件夹下所有文件并按修改时间倒序排列的方法
Oct 21 Python
python 删除字符串中连续多个空格并保留一个的方法
Dec 22 Python
详解如何在Apache中运行Python WSGI应用
Jan 02 Python
Python中一般处理中文的几种方法
Mar 06 Python
flask框架配置mysql数据库操作详解
Nov 29 Python
解决django xadmin主题不显示和只显示bootstrap2的问题
Mar 30 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实现ping
2006/10/09 PHP
10条PHP高级技巧[修正版]
2011/08/02 PHP
PHP隐形一句话后门,和ThinkPHP框架加密码程序(base64_decode)
2011/11/02 PHP
百度ping方法使用示例 自动ping百度
2014/01/26 PHP
PHP+MySQL实现消息队列的方法分析
2018/05/09 PHP
PHP合并两个或多个数组的方法
2019/01/20 PHP
laravel实现一个上传图片的接口,并建立软链接,访问图片的方法
2019/10/12 PHP
JS焦点图切换,上下翻转
2011/05/12 Javascript
JS自动适应的图片弹窗实例
2013/06/29 Javascript
Vue.js开发环境搭建
2016/11/10 Javascript
jquery mobile移动端幻灯片滑动切换效果
2020/04/15 Javascript
基于react框架使用的一些细节要点的思考
2017/05/31 Javascript
JavaScript实现图片切换效果
2017/08/12 Javascript
vue使用axios时关于this的指向问题详解
2017/12/22 Javascript
jQuery实现模糊查询的方法分析
2018/05/10 jQuery
bootstrap+spring boot实现面包屑导航功能(前端代码)
2019/10/09 Javascript
在vant中使用时间选择器和popup弹出层的操作
2020/11/04 Javascript
[48:47]VGJ.S vs NB 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/19 DOTA
跟老齐学Python之不要红头文件(2)
2014/09/28 Python
使用rpclib进行Python网络编程时的注释问题
2015/05/06 Python
CentOS7.3编译安装Python3.6.2的方法
2018/01/22 Python
Django项目开发中cookies和session的常用操作分析
2018/07/03 Python
使用Python操作FTP实现上传和下载的方法
2019/04/01 Python
在win64上使用bypy进行百度网盘文件上传功能
2020/01/02 Python
Python PyPDF2模块安装使用解析
2020/01/19 Python
Python爬虫与反爬虫大战
2020/07/30 Python
加拿大鞋网:Globo Shoes
2019/12/26 全球购物
说出数据连接池的工作机制是什么?
2013/04/19 面试题
建筑行业的大学生自我评价
2013/12/08 职场文书
供应链金融服务方案
2014/05/25 职场文书
好听的队名和口号
2014/06/09 职场文书
项目投资合作意向书
2014/07/29 职场文书
高中学校对照检查材料
2014/08/31 职场文书
高中班主任寄语
2019/06/21 职场文书
java代码实现空间切割
2022/01/18 Java/Android
Golang连接并操作MySQL
2022/04/14 MySQL