[IPython-dev] embedding ipython, namespace question

Darren Dale dsdale24 at gmail.com
Sat Dec 27 18:24:16 EST 2014


I passed None because
http://ipython.org/ipython-doc/stable/api/generated/IPython.terminal.embed.html?highlight=embed#IPython.terminal.embed.InteractiveShellEmbed
states: "If given as None, they are automatically taken from the scope
where the shell was called, so that program variables become visible." That
is precisely what I want, but can't figure out how to do it with the Qt
console.

I don't want to inject variables to an isolated namespace, I want the
console to share the application's namespace.

On Sat Dec 27 2014 at 6:02:54 PM Matthias Bussonnier <
bussonniermatthias at gmail.com> wrote:

>
> 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
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141227/4dabef80/attachment.html>


More information about the IPython-dev mailing list