[IPython-User] [IPython-user] using magic command inside the loop

Brian Granger ellisonbg@gmail....
Tue Dec 28 15:06:38 CST 2010

What version of IPython are you running?  When I run this on 0.10 I get:

Traceback (most recent call last):
  File "script.py", line 5, in <module>
    ip.magic('%run script_1.py')
AttributeError: 'NoneType' object has no attribute 'magic'

The reason is that an IPython interpreter has not been created.
Another option would be to name the scipy.pi to script.ipy and then

# script.ipy
for i in range(5):
    %run script_1.py


To run this do:

$ ipython scripy.py



On Tue, Dec 28, 2010 at 12:52 PM, unit <e_redekop@yahoo.com> wrote:
> Hi all,
> So, I want to use %run inside a for loop in my script.py to call for another
> script_1.py.
> Something like this:
> #beginning of script.py
> import IPython
> ip = IPython.ipapi.get()
> for i in range(0,5):
>          ip.magic('%run script_1.py')
> #end of the script.py
> However, when I execute script.py in my IPython shell, I get: "NameError:
> name 'ip' is not defined"
> My question is this: how come ip is not defined inside the for scope is I
> just defined it before entering the loop?
> Thank you very much for answering.
> --
> View this message in context: http://old.nabble.com/using-magic-command-inside-the-loop-tp30547307p30547307.html
> Sent from the IPython - User mailing list archive at Nabble.com.
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user

Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo

More information about the IPython-User mailing list