How do I reload a module after changing it?

后端 未结 4 1832
太阳男子
太阳男子 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:31

    Since this question asked specifically about PyCharm, please check out the answer on the PyCharm Support site. This answer is almost identical to @wokbot's, the distinction is that PyCharm removes the need to import importlib. It also uses the from ... import ... trick after import ... to make typing easier if you plan to use reloadtest frequently.

    In[2]: import ReloadTest
    In[3]: from ReloadTest import reloadtest
    In[4]: reloadtest(1)
    Out[4]: Version A: 1
    

    ...make changes

    In[5]: reload(ReloadTest)
    Out[5]: 
    In[6]: from ReloadTest import reloadtest
    In[7] reloadtest(2)
    Out[7]Version B: 2
    

提交回复
热议问题