美文网首页
python3中reload()的使用

python3中reload()的使用

作者: ugvibib | 来源:发表于2017-05-31 19:48 被阅读60次

在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'>
>>>

相关文章

网友评论

      本文标题:python3中reload()的使用

      本文链接:https://www.haomeiwen.com/subject/vlbjfxtx.html