I want to establish a standard script file that is imported into python at startup using the PYTHONSTARTUP environment variable. Additionally, I want to be able to conveniently reload the same script file after modifying it in an external editor, to test its behavior after the modification.
I created a ~/.pythonrc.py file and set it as PYTHONSTARTUP:

When I launch Python 3.1.2, .pythonrc is successfully executed and the workbench.py is imported, but dull_function does not appear in the global namespace or in a local one. What do I have to do differently?

workbench.dull_functuion yields a NameError. This is not surprising, as neither workbench nor dull_function appear in the namespace listed by dir() after the imports. imp.reload(workbench) returns a module object. Is there a way to intergrate this object manually into the global namespace?
–
neradisOct 25 '10 at 20:24

2 Answers
2

Move the import statement outside the function. You're basically importing the workbench module into the function scope, not the global scope (Try calling workbench.dull_function from inside load_wb to see for yourself).

Not really solving your immediate problem but... You might appreciate using iPython shell for testing in that case. Using the autoimport functionality, you can mark a module for (re)loading on each executed line if needed.

That means you can %aimport workbench and then every time you run some_function_Im_testing(), workbench will be reloaded if it changed. Just add the autoimport line into the configuration file for ipython and you're done.