reloading module which has been imported to another module

后端 未结 6 1053
难免孤独
难免孤独 2021-01-01 19:32

Let\'s face it, the whole business of reloading python code after changing it is a mess. I figured out awhile back that calling import at the in

6条回答
  •  再見小時候
    2021-01-01 19:51

    Rather than getting better at reloading modules, you could get better at restarting the interpreter. For example, you can put your setup code into its own file, and then run it like this:

    $ python -i setup.py
    >>>
    

    This will run setup.py, then leave you at the interactive prompt. Or, rather than doing a lot of work in the interactive prompt, write automated tests that do your work for you.

    You are right, reloading modules in Python is a mess. The semantics of the language make it difficult to change code while the process is running. Learn not to need reloading modules, you'll be happier.

提交回复
热议问题