Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically reload a python file when it is changed

Tags:

python

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?

like image 554
Naren Avatar asked Apr 23 '09 06:04

Naren


People also ask

How do I reload a modified module in Python?

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.

How do you refresh a Python script?

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.

What does the reload () function return in Python?

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.

How do I load a Python file in Python?

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.


1 Answers

Take at look at CherryPy's Autoreload feature. I think it looks quite simple and always worked well for me.

like image 51
optixx Avatar answered Sep 21 '22 10:09

optixx