>>> from foo import bar
successful to be imported
>>> from foo import bar
>>>
>>> reload(bar)
successful to be imported
<module 'foo.bar' from 'foo/bar.pyc'>
如果你使用的 python3 那方法就多了,详细请看下面 6 i0 g/ q& G9 q5 c. t重载模块方法二 * Y' l4 Y4 A, Z" S6 j- f 如果你使用 Python3.0 -> 3.3,那么可以使用 imp.reload 方法' B& V9 H! |, M4 \: q& ~; k
>>> from foo import bar
successful to be imported
>>> from foo import bar
>>>
>>> import imp
>>> imp.reload(bar)
successful to be imported
<module 'foo.bar' from '/Users/MING/Code/Python/foo/bar.py'>
>>> from foo import bar
successful to be imported
>>> from foo import bar
>>>
>>> import importlib
>>> importlib.reload(bar)
successful to be imported
<module 'foo.bar' from '/Users/MING/Code/Python/foo/bar.py'>
重载模块方法四, w& d: U6 h- {6 C
如果你对包的加载器有所了解,还可以使用下面的方法 $ O: t. ]* q( }8 t
>>> from foo import bar
successful to be imported
>>> from foo import bar
>>>
>>> bar.__spec__.loader.load_module()
successful to be imported
<module 'foo.bar' from '/Users/MING/Code/Python/foo/bar.py'>