How to reload python module imported using `from module import *`

前端 未结 8 1932
挽巷
挽巷 2020-12-02 14:12

I saw in this useful Q&A that one can use reload(whatever_module) or, in Python 3, imp.reload(whatever_module).

My question is, what if

8条回答
  •  有刺的猬
    2020-12-02 14:44

    A

    from module import *
    

    takes all “exported” objects from module and binds them to module-level (or whatever-your-scope-was-level) names. You can reload the module as:

    reload(sys.modules['module'])
    

    but that won't do you any good: the whatever-your-scope-was-level names still point at the old objects.

提交回复
热议问题