Reimport a module in python while interactive

前端 未结 6 1300
后悔当初
后悔当初 2020-11-27 08:45

I know it can be done, but I never remember how.

How can you reimport a module in python? The scenario is as follows: I import a module interactively and tinker wit

6条回答
  •  囚心锁ツ
    2020-11-27 09:25

    In python 3, reload is no longer a built in function.

    If you are using python 3.4+ you should use reload from the importlib library instead:

    import importlib
    importlib.reload(some_module)
    

    If you are using python 3.2 or 3.3 you should:

    import imp  
    imp.reload(module)  
    

    instead. See http://docs.python.org/3.0/library/imp.html#imp.reload

    If you are using ipython, definitely consider using the autoreload extension:

    %load_ext autoreload
    %autoreload 2
    

提交回复
热议问题