Python 字符编码实例,python编码实例,[Python]代码#c
Python 字符编码实例,python编码实例,[Python]代码#c
[Python]代码
#coding=utf-8 import sys print sys.getdefaultencoding() # --> ascii u1 = '中国' print type(u1), repr(u1) # --> <type 'str'> '\xe4\xb8\xad\xe5\x9b\xbd' u2 = u'中国2009' print type(u2), repr(u2) # --> <type 'unicode'> u'\u4e2d\u56fd2009' # str --> unicode print print '# str --> unicode' u1_1 = u1.decode('utf8') print type(u1_1), repr(u1_1) # --> <type 'unicode'> u'\u4e2d\u56fd' u1_2 = unicode(u1, 'utf8') print type(u1_2), repr(u1_2) # --> <type 'unicode'> u'\u4e2d\u56fd' # unicode --> str print print '# unicode --> str' u2_1 = u2.encode('utf8') print type(u2_1), repr(u2_1) # --> <type 'str'> '\xe4\xb8\xad\xe5\x9b\xbd2009' u2_2 = u2.encode('gbk') print type(u2_2), repr(u2_2) # --> <type 'str'> '\xd6\xd0\xb9\xfa2009' u2_3 = u2.encode('gb2312') print type(u2_3), repr(u2_3) # --> <type 'str'> '\xd6\xd0\xb9\xfa2009'
相关内容
- windows平台下如何用Python杀进程,平台python,[Python]代码
- Python脚本实现查找文件,,[Python]代码#c
- Python uuid模块,pythonuuid模块,python模块之uui
- 理解Python元类(Metaclasses),元类metaclasses,“元类的魔
- Python数组功能特点分析,python数组功能特点,实际上Py
- python 使用poplib pop3协议收取邮件,pythonpoplib,[Python]代码
- c,c++,java,python,ruby实现将文件读入数组的,pythonruby,c实现
- python从文本文件中选出使用频率最多的单词,,[Python]代
- python修改Windows注册表切换ie代理,pythonie,[Python]代码#
- python实现独身模式,python实现独身,class A:
评论关闭