如何重新加载使用`from module import *`导入的python模块 [英] How to reload python module imported using `from module import *`
本文介绍了如何重新加载使用`from module import *`导入的python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这个有用的问答中看到可以使用reload(whatever_module)
或者,在 Python 3 中,imp.reload(whatever_module)
.
I saw in this useful Q&A that one can use reload(whatever_module)
or, in Python 3, imp.reload(whatever_module)
.
我的问题是,如果我说 fromwhatever_module import *
来导入会怎样?然后当我使用 reload()
时,我没有 whatever_module
可以参考.你们会因为我将整个模块扔进全局命名空间而对我大喊大叫吗?:)
My question is, what if I had said from whatever_module import *
to import? Then I have no whatever_module
to refer to when I use reload()
. Are you guys gonna yell at me for throwing a whole module into the global namespace? :)
推荐答案
我同意一般不要这样做" 的共识,但是...
I agree with the "don't do this generally" consensus, but...
正确答案是:
import X
reload(X)
from X import Y # or * for that matter
这篇关于如何重新加载使用`from module import *`导入的python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文