# -*- coding: utf-8 -*-

import sys
reload(sys) # Python2.5 初始化后会删除 sys.setdefaultencoding 这个方法,我们需要重新载入
sys.setdefaultencoding(‘utf-8′)

str = ‘中文’
str.encode(‘gb18030′)

  一個回應 to “讓python的處理str的默認編碼為utf8”

  1. 你好哦,张茗学长让我来向各位学习哦。
    麻烦给个友情链接哦
    我的博客:http://www.centerday.com三袋弟子部落格
    已做好的你的链接了。
    谢谢哦。

 回覆

(必需)

(必需)

你可以使用以下語法 HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 Copy S. Liu 的部落格 Suffusion theme by Sayontan Sinha