Python编程中遇到NameError: name 'reload' is not defined 问题以及Python编码问题
来源:互联网 发布:学美工设计要什么基础 编辑:程序博客网 时间:2024/06/14 23:39
一、对于Python 2.X(建议使用Python2.7.X最新版本):
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
二、对于 <= Python 3.3:
import imp
imp.reload(sys)
注意:
1. Python 3 与python 2 有很大的区别,其中Python 3 系统默认使用的就是utf-8编码。
2. 所以,对于使用的是Python 3 的情况,就不需要sys.setdefaultencoding("utf-8")这段代码。
3. 最重要的是,Python 3 的sys 库里面已经没有 setdefaultencoding() 函数了。
三、对于 >= Python 3.4:(建议新手不要使用python3.X.X最新版本,降2个版本使用,最新版本资料少,不利于学习)
import importlib
importlib.reload(sys)
四、总结一下Python程序中涉及到的编码:
在开发Python 程序的过程中,会涉及到三个方面的编码:
1、Python 程序文件的编码。
我们在编写的程序本身也存在编码问题,一般的解决方式是在程序的开头加上“#coding=utf-8”或
“#coding=gbk”来使程序统一为UTF-8 或GBK 编码。
2、Python 程序运行时环境(IDE)的编码。
不是管是Sublime Text 或是PyCharm 也它,使用的IDE 工具也存在编码问题。如果你不确定是否是IDE
的编码引起程序出错的,根据我的经验,建议你切换回Python IDLE 去执行程序。
3、Python 程序读取外部文件、网页的编码。
当然,最容易出现编码问题应该是在读取外部数据或文件的时候。首先要确定读取的数据或文件的编码,
然后通过decode()和encode()方法来进行编码转换。
decode 的作用是将其他编码的字符串转换成Unicode 编码。
encode 的作用是将Unicode 编码转换成其他编码的字符串。
当我们在遇到Python 的编码问题时,从以上三个方法分析就会很容易找到解决编码问题的办法。
- Python编程中遇到NameError: name 'reload' is not defined 问题以及Python编码问题
- Python 解决 :NameError: name 'reload' is not defined 问题
- Python 解决 :NameError: name 'reload' is not defined 问题
- Python问题之“NameError: name 'reload' is not defined”
- Python 解决 :NameError: name 'reload' is not defined 问题
- 【python】-- NameError: name 'reload' is not defined
- 【Python】报错NameError: name 'reload' is not defined
- python NameError: name 'raw_input' is not defined
- 【Python】NameError:name ‘xrange’ is not defined
- Python NameError: name 'reduce' is not defined
- python NameError: name ' book ' is not defined
- NameError: name 'reload' is not defined
- 解决NameError: name 'reload' is not defined
- python reload(sys)找不到,name 'reload' is not defined
- Python 遇到NameError: name '_name_' is not defined这样的错误
- paip.python NameError name 'xxx' is not defined\
- python实例2—NameError: name 'file' is not defined
- 关于python-NameError: global name 'platform' is not defined
- Vue读取本地文件
- Java8
- uva 11584
- mysql 使用select插入多条数据,insert into (1,2,3,4,)select(1,2,3,4)
- Redis 有序集合
- Python编程中遇到NameError: name 'reload' is not defined 问题以及Python编码问题
- 设计模式——工厂模式
- Leetcode 128. Longest Consecutive Sequence:
- 三分钟了解Activity工作流
- 【python 图像识别】图像识别从菜鸟走向大神系列1
- springmvc拦截器验证
- 让枚举可以输出字符串
- nutz框架的添加和删除
- absolute同时设置left,right,top,bottom