You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The docs on Embedding IPython state about the embedded shell: "Note however that any changes you make to values while in the shell do not propagate back to the running code, so it is safe to modify your values because you won't break your code in bizarre ways by doing so."
My tests show that this is not true. When I call the following minimal script:
from __future__ import print_function
import IPython
a = 42
IPython.embed()
print("a={}".format(a))
And execute "a=23" in the embedded shell, then the program will output "a=23".
I think it's a side effect. I guess it would be ideal to be able to modify
variables in any scope, but python won't let us do that. Maybe global
variables should also not be modified, for consistency.
On 22 May 2014 08:41, "Olaf Lenz" [email protected] wrote:
Is it actually intended that one can modify the global namespace, but not
the local? Or is this a side-effect of how it is implemented?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/5887#issuecomment-43905455
.
Activity
takluyver commentedon May 22, 2014
I think modifying globals works, but modifying locals, when you embed
inside a function, doesn't.
olenz commentedon May 22, 2014
Indeed, that seems to be the case. When executing:
...changing a will not affect the output.
I will try to fix this in the docs.
olenz commentedon May 22, 2014
Is it actually intended that one can modify the global namespace, but not the local? Or is this a side-effect of how it is implemented?
takluyver commentedon May 23, 2014
I think it's a side effect. I guess it would be ideal to be able to modify
variables in any scope, but python won't let us do that. Maybe global
variables should also not be modified, for consistency.
On 22 May 2014 08:41, "Olaf Lenz" [email protected] wrote:
oldclesleycode commentedon Nov 10, 2017
working on the documentation change!
jzf2101 commentedon Nov 10, 2017
@minrk do you mean this only to be a documentation change and not a change to the underlying behavior?
minrk commentedon Nov 10, 2017
That’s the immediate issue, yes.
takluyver commentedon Mar 29, 2018
Fixed by #10891