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

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

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

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

復制代碼 代碼如下:

import sys
print sys.getdefaultencoding()

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

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

修改成utf-8
復制代碼 代碼如下:

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

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

[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)過查找相關資料,才發(fā)現(xiàn)早期版本可以直接sys.setdefaultencoding('utf-8'),新版本需要先reload一下
復制代碼 代碼如下:

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

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

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

 

相關文章

最新評論

同仁县| 湟中县| 繁峙县| 广昌县| 洪洞县| 盐源县| 江阴市| 定结县| 平罗县| 南涧| 攀枝花市| 新巴尔虎左旗| 阳山县| 靖宇县| 静乐县| 青铜峡市| 门源| 集贤县| 广饶县| 沈丘县| 岳西县| 武宣县| 中超| 雷波县| 汶上县| 夏邑县| 深圳市| 麻城市| 奎屯市| 濮阳市| 五家渠市| 都兰县| 县级市| 泌阳县| 繁昌县| 山阳县| 石狮市| 梓潼县| 广饶县| 增城市| 绵竹市|