How do I reload a module after changing it?

后端 未结 4 1834
太阳男子
太阳男子 2020-12-09 09:51

Python Console with Python 3.4.2

I defined a function in a module which runs correctly in Python Console in PyCharm Community Edition 4.5.4:
ReloadTest.py:

4条回答
  •  轮回少年
    2020-12-09 10:26

    Get it to work!
    Instead of from Module import function, I should import the whole module import Module, then call the function by Module.function(). This is because

    from ReloadTest import reloadtest
    

    and

    importlib.reload(ReloadTest)
    

    can't go together.

    >>> import ReloadTest
    >>> ReloadTest.reloadtest(1)
    Version A: 1
    

    After making changes:

    >>> importlib.reload(ReloadTest)
    
    >>> ReloadTest.reloadtest(2)
    Version B: 2
    

提交回复
热议问题