tags:

views:

70

answers:

2

I'm new to python (and to programming in general) and here I have a newbie question:

let's say I have this python script "script.py" and I load it in the interpreter by typing

import script

and then I execute my function by typing:

script.testFunction(testArgument)

OK so far so good, but when I change "script.py", if I try to import again the script doesn't update. I have to exit from the interpreter, restart the interpreter, and then import the new version of the script for it to work.

What should I do instead?

Thanks in advance.

+5  A: 

You can issue a reload script, but that will not update your existing objects and will not go deep inside other modules.

Fortunately this is solved by IPython - a better python shell which supports auto-reloading. If you run %autoreload 1 and then %aimport script, then the module will be reloaded before every REPL command. This will not update any existing objects however.

To use autoreloading in ipython, you'll have to use import ipy_autoreload first, or put it permanently in your ~/.ipython/ipy_user_conf.py

viraptor