If I make some changes to one of the files belonging to a running app, is there a way to tell the python runtime to automatically reload the module/file?
The reload() is used to reload a previously imported module or loaded module. This comes handy in a situation where you repeatedly run a test script during an interactive session, it always uses the first version of the modules we are developing, even we have made changes to the code.
In this article, we present the approach to implement a Python script that can refresh an URL / Tab in the browser. Manually, this can be done by pressing F5 key.
The reload() is a previously imported module. If you've altered the module source file using an outside editor and want to test the updated version without leaving the Python interpreter, this is helpful. The module object is the return value.
You need to tell python to first import that module in your code so that you can use it. If you have your own python files you want to import, you can use the import statement as follows: >>> import my_file # assuming you have the file, my_file.py in the current directory.
Take at look at CherryPy's Autoreload feature. I think it looks quite simple and always worked well for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With