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

Lie Ryan lie.1296 at gmail.com
Mon Dec 19 05:54:37 EST 2011


On 12/19/2011 12:16 AM, nukeymusic wrote:
> On 18 dec, 13:39, Lie Ryan<lie.1... at gmail.com>  wrote:
>> On 12/18/2011 10:00 PM, nukeymusic 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
>>> I do know how to run the script non-interactively, but what I want to
>>> do is adding lines to the code I have written thus far in interactive
>>> mode.
>>
>>> thanks in advance
>>> nukey
>>
>> The normal python shell doesn't directly support doing that, although
>> there are several workaround with (ab)using the 'import' statement, it
>> had several subtleties with how module are cached. Try the ipython
>> shell; in ipython you can load a file into the current interpreter
>> session using the %run magic command.
>
> I guess you mean the following command?
> %run 'myscript.py'
>
> is this correct?

yes





More information about the Python-list mailing list