python 字符串编码

经过字符串的decode和encode方法python

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]]) 下面是字符串编码应用:
spa

a = '你好'
b = 'python'
print a . decode( 'utf-8') . encode( 'gbk') ##decode方法把字符串转换为unicode对象,而后经过encode方法转换为指定的编码字符串对象
print b . decode( 'utf-8') ##decode方法把字符串转换为unicode对象
相关文章
相关标签/搜索