星期三, 九月 05, 2007

Python转码

简单的方法就是 str=str.decode("gb2312").encode("utf-8")'
decode是为了得到unicode字符串,encode回到utf-8编码。
如果编码选择错误或者字符内容编解码错误都会触发相应的异常。

最终encode得到的字符串如果和OS的编码(locale)不一致的话,print时就会出现乱码。

0 Comments:

发表评论

<< Home