I have Python scripts that use the if __name__ == \'__main__\'
trick to have some code only run when the script is called as a script and not when it is loaded
It sounds like you might just need the -x
switch:
In [1]: %edit
IPython will make a temporary file named: /tmp/ipython_edit_J8j9Wl.py
Editing... done. Executing edited code...
Name is main -- executing
Out[1]: "if __name__ == '__main__':\n print 'Name is main -- executing'\n"
In [2]: %edit -x /tmp/ipython_edit_J8j9Wl
Editing...
When you call %edit -x
the code is not executed after you exit your editor.