[IPython-user] %run foo.ipy crashes on blank lines, but %edit foo.ipy works OK

Fernando Perez fperez.net@gmail....
Tue Jun 3 14:54:25 CDT 2008

On Tue, Jun 3, 2008 at 8:46 AM, Matthew Wilson <matt@tplus1.com> wrote:
> I find myself writing scripts that depend on a highly-customized ipython
> session to run.
> For example, my ipython session creates database connections and loads
> lots of modules.
> Then my script just does the interesting stuff.
> First I start up ipython with my specialized profile:
>    ipython -p with-database-connection
> then in ipython, I run %edit blah.py
> And then immediately close the editor.
> Then all the objects in blah.py are now in the top-level namespace, and
> I can run everything.
> It's a minor detail, but using %edit to open and then immediately close
> the editor seems silly.
> I tried %run, but that runs my script in an empty namespace, and then
> populates the top level.  No good.

Try %run -i foo.py.  This runs foo.py in your interactive namespace,
so all top-level names are seen by your script.  The difference is

- %run: runs in empty namespace, updates top-level.
- %run -i: runs directly in top-level, as if 'typed in'

In addition, as Ville said the whitespace problems should have been
fixed now.  But if I understood your question correctly, run -i is
what you want.



More information about the IPython-user mailing list