最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python錯(cuò)誤:AttributeError: 'module' object has no attribute 'setdefaultencoding'問題的解決方法

 更新時(shí)間:2014年08月22日 09:20:53   投稿:junjie  
這篇文章主要介紹了python錯(cuò)誤:AttributeError: 'module' object has no attribute 'setdefaultencoding'問題的解決方法,需要的朋友可以參考下

Python的字符集處理實(shí)在蛋疼,目前使用UTF-8居多,然后默認(rèn)使用的字符集是ascii,所以我們需要改成utf-8
查看目前系統(tǒng)字符集

復(fù)制代碼 代碼如下:

import sys
print sys.getdefaultencoding()

執(zhí)行:
復(fù)制代碼 代碼如下:

[root@lee ~]# python a.py
ascii

修改成utf-8
復(fù)制代碼 代碼如下:

import sys
 
sys.setdefaultencoding('utf-8')
 
print sys.getdefaultencoding()

執(zhí)行:
復(fù)制代碼 代碼如下:

[root@lee ~]# python a.py
Traceback (most recent call last):
  File "a.py", line 4, in <module>
    sys.setdefaultencoding('utf-8')
AttributeError: 'module' object has no attribute 'setdefaultencoding'
提示:AttributeError: 'module' object has no attribute 'setdefaultencoding'?

后來經(jīng)過查找相關(guān)資料,才發(fā)現(xiàn)早期版本可以直接sys.setdefaultencoding('utf-8'),新版本需要先reload一下
復(fù)制代碼 代碼如下:

import sys
 
reload(sys)
sys.setdefaultencoding('utf-8')
 
print sys.getdefaultencoding()

執(zhí)行
復(fù)制代碼 代碼如下:

[root@lee ~]# python a.py
utf-8

 

相關(guān)文章

最新評(píng)論

金溪县| 宁乡县| 黄龙县| 广宗县| 睢宁县| 芦溪县| 牙克石市| 长白| 安泽县| 桂东县| 乌兰县| 东辽县| 重庆市| 绥化市| 锦屏县| 安康市| 平阴县| 绍兴县| 裕民县| 建湖县| 新蔡县| 凤翔县| 新干县| 定南县| 新郑市| 江川县| 稷山县| 石家庄市| 韶山市| 罗江县| 延长县| 湟源县| 永年县| 顺义区| 丰宁| 沛县| 池州市| 伊春市| 万荣县| 奇台县| 江孜县|