How to tell Python to reimport my script?
本问题已经有最佳答案,请猛点这里访问。
我在bash中启动的Python环境中运行我的脚本:
1 | >>> import myscript |
然后我稍微修改了我的脚本并保存它。 然后又跑了
1 | >>> import myscript |
但它不会运行更新的脚本。
如何告诉Python运行更新的? 谢谢!
只需
1 | reload(myscript) |
引用文档,
Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter.
重新加载内置是你真正需要的:
https://docs.python.org/2/library/functions.html#reload