[IPython-user] start ipython from my own script

Ondrej Certik ondrej@certik...
Sun May 31 19:32:16 CDT 2009


On Sun, May 31, 2009 at 6:06 PM, Ondrej Certik <ondrej@certik.cz> wrote:
> On Sat, May 30, 2009 at 8:19 PM, Gökhan SEVER <gokhansever@gmail.com> wrote:
>> Ondrej,
>>
>> Do you know how to instantiate --pylab in the similar fashion (from a shell
>> call and dropping into pylab enabled Ipython session) ?
>
> Unfortunately I don't know, but try to investigate what the --pylab
> option really does and then there are maybe some kwarguments how to do
> it. Or just patch ipython to do it and send a patch.
>
> To all --- I am using the following combination quite often now:
>
> import IPython
> IPython.Shell.IPShell(user_ns=locals()).mainloop()

Actually, to emulate pdb.set_trace(), I want to be able to access both
locals and globals, e.g. here is my line:

        IPython.Shell.IPShell(user_ns=dict(globals(), **locals())).mainloop()

I tried to implement this:

$ bzr diff
=== modified file 'IPython/__init__.py'
--- IPython/__init__.py	2009-03-17 03:05:22 +0000
+++ IPython/__init__.py	2009-06-01 00:29:16 +0000
@@ -59,6 +59,13 @@

 import Shell

+def set_trace():
+    """
+    Starts the IPython shell with the user namespace set to union of globals()
+    and locals().
+    """
+    Shell.IPShell(user_ns=dict(globals(), **locals())).mainloop()
+
 # Release data
 from IPython import Release # do it explicitly so pydoc can see it - pydoc bug
 __author__   = '%s <%s>\n%s <%s>\n%s <%s>' % \



But it's not easy, the above doesn't work.. It's because globals() and
locals() are different inside that set_trace() function. So I think it
will require more hacking with frames. Before I try to do it --- would
you accept such a patch to ipython?

Ondrej


More information about the IPython-user mailing list