python错误:AttributeError: 'module' object has
发布时间:2020-12-16 20:01:29 所属栏目:Python 来源:网络整理
导读:Python的字符集处理实在蛋疼,目前使用UTF-8居多,然后默认使用的字符集是ascii,所以我们需要改成utf-8 查看目前系统字符集 复制代码 代码如下: import sys print sys.getdefaultencoding() 执行: 复制代码 代码如下: [root@lee ~]# python a.py ascii 修
Python的字符集处理实在蛋疼,目前使用UTF-8居多,然后默认使用的字符集是ascii,所以我们需要改成utf-8 复制代码 代码如下: 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 OpenCV – 无法检测到微小的“漏洞”(圆圈)
- python – 在Pandas DataFrame中查找所有最大索引
- python将图片转base64,实现前端显示
- python – 按用户定义的月份范围对pandas dataFrame进行分组
- python – PyMinuit与IMinuit
- python – Pandas Dataframe对象在不同的??数据类型上输入f
- python修改注册表终止360进程实例
- python – 正则表达式从给定类型的字符串中获取多个日期
- python – NetworkX From_Pandas_dataframe
- Python编程之序列操作实例详解