How to reload a module's function in Python?

后端 未结 8 1815
遥遥无期
遥遥无期 2020-11-28 09:27

Following up on this question regarding reloading a module, how do I reload a specific function from a changed module?

pseudo-code:

from foo import b         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 09:43

    You can't reload a method from a module but you can load the module again with a new name, say foo2 and say bar = foo2.bar to overwrite the current reference.

    Note that if bar has any dependencies on other things in foo or any other side effects, you will get into trouble. So while it works, it only works for the most simple cases.

提交回复
热议问题