[IPython-user] Embedded IPython and -pylab

Inigo Aldazabal Mensa inigo_aldazabal@ehu...
Mon Sep 15 03:56:42 CDT 2008

El Sábado, 13 de Septiembre de 2008 11:09, Ville M. Vainio escribió:

> > Any idea on how could I inherit the whole previous namespace into the
> > newly created IPython session? And regarding this, I understand that
> Try doing ip.user_ns.update(globals()) in the embedding code.

Thank you very much, that was what I was looking for.

> > the "exported" variables get duplicated in memory, am I rigth?
> No, they are not duplicated in the memory. It's how python object
> model works in general - only the names are created that point to the
> objects themselves.

That is what I thought first, but then if I change the variables inside the 
ipython instance, the change does not propagate when I go out from it, eg: 

import IPython.ipapi
import IPython.Shell

print "a: ", a
shellclass = IPython.Shell._select_shell(['ipython', '-pylab'])
ses = IPython.ipapi.make_session(shellclass=shellclass)
ip = ses.IP.getapi()
print "a: ", a

If inside ipython I change the value of a, it doesn't  remain changed when 
I exit from it.

Why is this?

mmm... while writting this I checked a bit more and it seems to be related 
on how python itself treats variable aliasing. 

>>> a=1
>>> b=a
>>> b is a
>>> b=2
>>> b is a
>>> a

I think I understand what happens, but I'll have to think about it a bit 

Thanks for your help.

More information about the IPython-user mailing list