Proper way to reload a python module from the console

前端 未结 8 1945
迷失自我
迷失自我 2020-12-03 04:51

I\'m debugging from the python console and would like to reload a module every time I make a change so I don\'t have to exit the console and re-enter it. I\'m doing:

<
8条回答
  •  星月不相逢
    2020-12-03 05:15

        from test_reload import add_test
    

    where test_reload is a module, and add_test is a function if you changed the function add_test, of course you need to reload this function. then you can do this:

    
        import imp
        imp.reload(test_reload)
        from test_reload import add_test
    

    this will refresh the function add_test.

    so you need to add

    imp.reload(test_reload)
    from test_reload import add_test  --add this line in your code
    

提交回复
热议问题