[IPython-user] start ipython from my own script

Ondrej Certik ondrej@certik...
Sat May 30 21:03:04 CDT 2009


On Sat, May 30, 2009 at 7:55 PM, Ondrej Certik <ondrej@certik.cz> wrote:
> Hi,
>
> I have a program or script and at one point I would like to start an
> ipython shell and pass all my local/global variables into it, so that
> I can experiment. Importing the whole script in ipython session
> doesn't help, because I want to run ipython at some particular point.
> E.g something like an enhanced version of:
>
> import pdb
> pdb.set_trace()
>
> So far I tried:
>
> import IPython
> ipython = IPython.Shell.start()
> ipython.mainloop()
>
>
> that works, but I don't see the variables from the program. What is
> the best way to do that?

Here is how:

import IPython
shell = IPython.Shell.IPShell(user_ns=locals())
shell.mainloop()

Pretty cool!

Ondrej


More information about the IPython-user mailing list