How can I reload objects in my namespace in ipython [duplicate]

可紊 提交于 2019-12-18 04:29:18

问题


After import functions into ipython, how do I reload them when I have modified them outside of ipython ?


回答1:


Python 2:

reload(module)

Python 3:

from importlib import reload
reload(module)

Where module is the file with your functions.




回答2:


you can also use autoreload, so that the modules you are working on are automatically reloaded at each statement, pretty handy for debugging, see:

Autoreload of modules in IPython




回答3:


Use the following link to read more about reload built-in function. Please find sample below:

import controls.grid
reload(controls.grid)

Note that reload is 'Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before.' and 'When a module is reloaded, its dictionary (containing the module’s global variables) is retained. Redefinitions of names will override the old definitions, so this is generally not a problem. If the new version of a module does not define a name that was defined by the old version, the old definition remains.'



来源:https://stackoverflow.com/questions/6420361/how-can-i-reload-objects-in-my-namespace-in-ipython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!