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

2011-12-20 Thread kimma

Am 18.12.2011 12:00, schrieb nukeymusic:

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


In console, do "python script.py" (after cd'ing into the right directory)
--
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-20 Thread Admin

Am 18.12.2011 12:00, schrieb nukeymusic:

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
just go to the folder there there script is located and then do 
"scriptname.py"

--
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-19 Thread Lie Ryan

On 12/19/2011 12:16 AM, nukeymusic wrote:

On 18 dec, 13:39, Lie Ryan  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


--
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-18 Thread nukeymusic
On 18 dec, 13:39, Lie Ryan  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?

thanks
nukey
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-18 Thread Lie Ryan

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.


--
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-18 Thread Kev Dwyer
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

Hello,

You can make the code in your script available to the interpreter by typing 

import myscript

(assuming that you are running the interpreter in the same directory that 
contains myscript.py)

You can access functions, classes and other top-level objects in your script 
by prefixing their names with "myscript" and a dot (".") e.g. 
myscript.myfunc, myscript.MyClass, myscript.myvar

You can't really edit your script in the interpreter, but you can edit and 
save in a text editor and then type 

reload(myscript) 

in the interpreter to refresh its version of the myscript code.

N.B. when you import/reload your script the interpreter will immediately 
execute any code that is not enclosed in a function or class definition.

Cheers,

Kev

-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-18 Thread Chris Angelico
On Sun, Dec 18, 2011 at 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

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
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2011-12-18 Thread nukeymusic
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
-- 
http://mail.python.org/mailman/listinfo/python-list