python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
2017-11-23 00:00
1771 查看
Python的字符集处理实在蛋疼,目前使用UTF-8居多,然后默认使用的字符集是ascii,所以我们需要改成utf-8
查看目前系统字符集
执行:
修改成utf-8
执行:
复制代码代码如下:
提示:AttributeError: 'module' object has no attribute 'setdefaultencoding'?
后来经过查找相关资料,才发现早期版本可以直接sys.setdefaultencoding('utf-8'),新版本需要先reload一下
复制代码代码如下:
执行
复制代码代码如下:
查看目前系统字符集
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
相关文章推荐
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- Python问题分析:AttributeError: module 'sys' has no attribute 'setdefaultencoding'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 【python学习笔记(2)】脚本报错"AttributeError: 'module' object has no attribute 'xxx'"解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 关于python里运行出现'module' object has no attribute 'xxxx'等问题解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: 'module' object has no attribute '_handlerList' 错误解决方法
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- Tensorflow protobuf版本报错问题解决(AttributeError: 'module' object has no attribute 'Default')
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- GNU Radio自定义模块在添加到流图后运行报‘module’ object has no attribute错误的解决方法