how to “reimport” module to python then code be changed after import

前端 未结 4 712
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 12:37

I have a foo.py

def foo():
    print \"test\"

In IPython I use:

In [6]:  import foo
In [7]:  foo.foo()
test
         


        
4条回答
  •  無奈伤痛
    2020-12-02 13:14

    In addition to gnibbler's answer:

    This changed in Python 3 to:

    >>> import imp
    >>> imp.reload(foo)
    

    As @onnodb points out, imp is deprecated in favor of importlib since Python 3.4:

    >>> import importlib
    >>> importlib.reload(foo)
    

提交回复
热议问题