Python 也提供了重新加载已加载模块的基本支持.
[Example 1-8 #eg-1-8 会加载 3 次 hello.py 文件.
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 直接创建的到模块内容的引用也是不会被更新的.