[IPython-user] (newbie) Can an embedded ipython propegate changes to the caller?
Fernando Perez
Fernando.Perez at colorado.edu
Tue Jul 26 16:45:23 CDT 2005
ipython-user at barillari.org wrote:
> Hi,
>
> I'm curious if there's an easy way to hack ipython so that an embedded
> ipython interpreter _can_ make changes to the calling frame --- in other
> words, circumventing the "any changes you make to values while in the shell
> do not propagate back to the running code" note in the manual.
>
> I imagine this would involve linking rather than copying the caller's
> namespace in the in embed_mainloop() (in other words, using local_ns
> (call_frame.f_locals) directly rather than copying it into user_ns), but I
> thought I'd post here before trying that to see if there was a more elegant
> solution.
I recall when I wrote that code reading that the CPython interpreter makes no
guarantees about the locals objects being writable in any useful sense of the
word. More specifically, the CPython VM reserves the right to hand you a
proxy object for the frame locals which you can write to, but any changes made
to that object don't necessarily propagate back.
Feel free to experiment further, but in the absence of an explicit guarantee
from the python docs that this is valid, I can't include it in any shipping
version. It is something that _might_ work by accident for any random version
of the VM, but which could stop working any time if they change the internals.
Granted, things may have changed since I did that work, so if you can find
confirmation that under current python the frame locals are _explicitly_
guaranteed to be a writeable object, I'd be glad to change it. But I strongly
doubt this to be the case.
Cheers,
f
More information about the IPython-user
mailing list