When writing or debugging a Python program, I really like using the -i command line switch to be able to directly inspect my functions without having to run everything from start to finish.
However, whenever I make a change to the code I have to close and restart my interactive session, losing all temporary variables that I might have defined. How do I reload my source file from within the python interpreter?
The builtin function reload looks like it was made for this, but I can only use it with named modules:
>> import my_prog >> print my_prog.x -- prints an error, because x is not defined -- -- edited my_prog.py to add the x global now... >> reload(my_prog) >> print my_prog.x -- prints x However, if I instead to do a from my_prog import * in the beginning reload doesn't work, and doing the import again also has no effect.