python里使用reload函数

来源:互联网 发布:淘宝充值可以赚信誉吗 编辑:程序博客网 时间:2024/06/05 20:03
reload函数是使用模块名称,而不是变量名称,也就是说当你把它改变了名称,它也是加载原来的名称。

当使用reload时,这个模块会被重新编译,新的模块替换原来的模块。如果之前从这个模块创建的实例仍然使用旧的模块实现。特别是使用from-import语句加载的名称,也不会被更新。

例如:

# File: builtin-reload-example-1.pyfrom imp import reloadimport helloreload(hello)reload(hello)

输出如下:

=== RESTART: D:/work/csdn/python_Game1/example/builtin-reload-example-1.py ===
hello again, and welcome to the show
hello again, and welcome to the show
hello again, and welcome to the show
>>> 

这里helo.py代码如下:

print('hello again, and welcome to the show')

1. 如果模块在语法上是正确的,但在初始化过程中失败,则导入过程不能正确地将模块的名字绑定到符号表中。这时,必须在模块能被重新加载之前使用import()函数加载该模块。
2. 重新加载的模块不删除最初旧版本模块在符号表中的登记项。
3. 如果一模块利用from。。。import。。。方式从另一模块导入对象,reload()函数不重新定义导入的对象,可利用import。。。形式避免这个问题。
4. 提供类的重新加载模块不影响所提供类的任何已存实例---已存实例将继续使用原来的方法定义,只有该类的新实例使用新格式。这个原则对派生类同样适用。


Python游戏开发入门

http://edu.csdn.net/course/detail/5690

你也能动手修改C编译器

http://edu.csdn.net/course/detail/5582

纸牌游戏开发

http://edu.csdn.net/course/detail/5538 

五子棋游戏开发

http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通 
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战 
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用 
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672