how to run python-script from the python promt? [absolute newbie]

Chris Angelico rosuav at gmail.com
Sun Dec 18 06:29:49 EST 2011


On Sun, Dec 18, 2011 at 10:00 PM, nukeymusic <nukeymusic at gmail.com> wrote:
> How can I load a python-script after starting python in the
> interactive mode?
> I tried with
>>>>load 'myscript.py'
>>>>myscript.py
>>>>myscript
>
> but none of these works, so the only way I could work further until
> now was copy/paste line per line of my python-script to the
> interactive mode prompt

The easiest way to load a file is to import it. However, this is not
quite identical to loading the script into the current session. If
your script mainly defines functions, you can either:

import myscript

or

from myscript import *

and it'll do more or less what you expect; however, it will execute in
its own module context, so globals from your current session won't be
available to it.

Tip for pasting: Indent every line of your code at least one
space/tab, prefix it with "if True:", and then you can paste it all at
once.

ChrisA



More information about the Python-list mailing list