python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
作者:junjie 时间:2021-09-15 16:28:22
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,AttributeError
0
投稿
猜你喜欢
asp精妙的SQL语句例子
2008-03-04 17:42:00
ASP编程代码:隐藏图片的真实地址
2008-10-19 17:14:00
Mysql入门系列:MySQL数据目录的位置
2008-11-24 12:59:00
一篇文章带你学习python的函数与类
2023-10-15 05:04:18
提高ASP性能的最佳选择第二部分
2007-08-15 12:46:00
Python Django2 model 查询介绍(条件、范围、模糊查询)
2023-11-02 15:32:09
详解AJAX核心 —— XMLHttpRequest 对象
2010-03-31 14:49:00
python科学计算之numpy——ufunc函数用法
2023-05-13 15:13:12
python关键字传递参数实例分析
2023-08-24 04:28:34
Golang算法问题之数组按指定规则排序的方法分析
2023-10-06 01:37:14
用CSS3将你的设计带入下个高度[译]
2009-06-22 13:03:00
轻松掌握SQL Server数据库的六个实用技巧
2009-01-15 12:56:00
Golang利用casbin实现权限验证详解
2023-08-06 23:18:45
14条最佳JS代码编写技巧[译]
2009-11-09 19:37:00
Asp Object 之:AddHeader
2008-05-05 12:58:00
python中如何使用insert函数
2023-08-02 17:04:43
python 中的jieba分词库
2023-08-10 01:26:30
纯CSS制作的网页中的lightbox效果
2007-11-06 18:59:00
友情连接地址代码-线线表格
2010-07-01 16:26:00
解决MySQL启动时1067错误
2010-09-30 14:09:00