您的位置:首页 > 编程语言 > Python开发

Python 也提供了重新加载已加载模块的基本支持

2017-11-11 12:12 381 查看
Python 也提供了重新加载已加载模块的基本支持.

[Example 1-8 #eg-1-8 会加载 3 次 hello.py 文件.  

1.2.2.5. Example 1-8. 使用 reload 函数  

File: builtin-reload-example-1.py

 

import hello

reload(hello)

reload(hello)

 

 

 

 

 

 

 

hello again, and welcome to the show

hello again, and welcome to the show

hello again, and welcome to the show

 

reload 直接接受模块作为参数. 

 
注意:当你重加载模块时, 它会被重新编译, 新的模块会代替模块字典里的老模

块. 但是, 已经用原模块里的类建立的实例仍然使用的是老模块(不会被更新).  

同样地, 使用 from-import 直接创建的到模块内容的引用也是不会被更新的. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: