[IPython-user] Using IPShellEmbed

Frédéric Mantegazza mantegazza at ill.fr
Wed Oct 11 03:02:48 CDT 2006

Le mardi 10 octobre 2006 19:18, Fernando Perez a écrit :

> This isn't really supported out of the box.  I can have a look later,
> but in the meantime, here's the outline of what I'd do in case you
> want to try it yourself.  Start by doing this as a subclass of
> IPShellEmbed, if the approach works we can add a cleaner API for the
> next release.
> Subclass IPShellEmbed and override runlines, so that it takes local_ns
> and global_ns much like __call__ does.  Then, make your new runlines()
> be basically a merge of the existing one and a copy of
> embed_mainloop() (found in iplib), where you replace the call
> self.interact(header)
> with the previous runlines() actions.
> This is what I'd do just to get a quick and dirty test of whether the
> whole idea works correctly and does what you need.  If the answer is
> yes, then we can easily modify the APIs to do this without such
> copy/paste hacks.

Thanks for the answer.

Looking in the code, I found a 'user_ns' parameter in the IPShellEmbed 
__init__() method. I tried to use it to set my context, and it seems to 
work. The difference is that objects registered in that 'user_ns' context 
are not seen whith the 'who' command, but are available.

What is exactly the purpose of this parameter? May I use it for what I want 
to do?


More information about the IPython-user mailing list