查看目前系统字符集
import sys print sys.getdefaultencoding()执行:
[root@lee ~]# python a.py ascii修改成utf-8
import sys sys.setdefaultencoding('utf-8') print sys.getdefaultencoding()执行:
[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'?
后来经过查找相关资料,才发现早期版本可以直接sys.setdefaultencoding('utf-8'),新版本需要先reload一下
import sys reload(sys) sys.setdefaultencoding('utf-8') print sys.getdefaultencoding()执行
[root@lee ~]# python a.py utf-8
查看更多关于AttributeError: module object has no attribute set的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did8162