python 字符串编码

通过字符串的decode和encode方法

1 encode([encoding,[errors]])
#其中encoding可以有多种值,比如gb2312 gbk gb18030 bz2 zlib big5 bzse64等都支持。errors默认值为"strict",意思是UnicodeError。可能的值还有'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace' 和所有的通过codecs.register_error注册的值。

S.decode([encoding,[errors]]) 下面是字符串编码应用:

a = '你好'
b = 'python'
print a.decode('utf-8').encode('gbk')##decode方法把字符串转换为unicode对象,然后通过encode方法转换为指定的编码字符串对象
print b.decode('utf-8')##decode方法把字符串转换为unicode对象
posted @ 2013-08-10 21:07  老王python  阅读(1073)  评论(0编辑  收藏  举报