python3中reload()的使用

2017-05-31  本文已影响60人  ugvibib

在python3中已经不能直接使用reload()了
然后在测试代码中,reload()还是经常被使用的。
例如:

>>> import firstpython.firstpython
>>> reload(firstpython.firstpython)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'reload' is not defined
>>>

当我对firstpython.firstpython中的代码修改后,想再导入一遍,测试一下是否正确,但发现,已经不能导入第二次了,这时候reload()就发挥它的作用了。

>>>from imp import reload
>>> reload(firstpython.firstpython)
hello,world
hello,world
hello,world
hello,world
hello,world
<module 'firstpython.firstpython' from 'C:\\Users\\win10\\Documents\\study\\firstpython\\firstpython.py'>
>>>
上一篇 下一篇

猜你喜欢

热点阅读