How to run script from interpreter?

windhorn aewindhorn at gmail.com
Mon Feb 19 13:05:05 EST 2018


On Saturday, February 17, 2018 at 8:50:48 AM UTC-6, Steven D'Aprano wrote:
> 
> For me, the tool I use is a set of re-usable tools:
> 
> - a text editor;
> - a system command prompt in a terminal/console window;
> - a Python REPL for running code snippets and looking up help(obj).
> 
> Other people prefer a IDE like Spyder (or many others). Either way, 
> they're designed for the edit-run-debug-edit cycle.

I hadn't looked at Spyder, it seems very useful.

> I edit the source code of my script in the text editor, then run it from 
> the command prompt using
> 
>     python myscript.py
> 
> If I need the debugger, I use:
> 
>     python -i myscript.py
> ... 
> then edit the script to make the tests work.
> 
> The best part of this is each time you run the script, it is guaranteed 
> to be running *fresh*, with no left-over cruft from previous runs.

Good point. But some of that is stuff I'm using, so maybe it has to go in the script.

And this from Ian seems to work for me:

> py> import foo  # Get the module to reload
> py> reload(foo)  # Reload it
> py> from foo import *  # Update all the names previously *-imported

Thanks all for some good advice.

Regards,
Allen



More information about the Python-list mailing list