[IPython-dev] embedding ipython, namespace question

Matthias Bussonnier bussonniermatthias at gmail.com
Sat Dec 27 18:02:45 EST 2014


Le 27 déc. 2014 à 23:43, Darren Dale <dsdale24 at gmail.com> a écrit :

> Thanks Ray. Unfortunately, I want the ipython console's namespace to reflect that of the application in which it is embedded, not a specific widget. There is an example that appears to do this at https://github.com/ipython/ipython/blob/master/examples/Embedding/embed_function.py , but I'm trying to do the same with the Qt widget. At the top of my main gui module, I do:
> 
> try:
>     from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
>     from IPython.qt.inprocess import QtInProcessKernelManager
> 
>     # Create an in-process kernel
>     kernel_manager = QtInProcessKernelManager(user_ns=None)

Don't you want to just pass `globals()` instead of `None` here? 
user_ns kwarg here is **the mutable namespace** (i.e. a dict) you want your kernel to work on.  If you pass None, 
it will create a new empty object for you. If you pass `{"a":1}` then your kernel will see a variable `a` with a value of 1 (mutable) 

So I guess what you want to pass here is either globals(), locals(), or a dict you constructed yourself, 
from the bit you want available. 

You can also do as raymond said, and inject things into user_ns after getting the reference to it. 
-- 
M

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141228/20e6f5b9/attachment.html>


More information about the IPython-dev mailing list