Skip to content

Docs: Embedding IPython #5887

Closed
Closed

Description

@olenz

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".

Do I misunderstand the docs, or what is wrong?

Activity

  1. takluyver commented on May 22, 2014

    @takluyver
    Member

    I think modifying globals works, but modifying locals, when you embed
    inside a function, doesn't.

  2. olenz commented on May 22, 2014

    @olenz
    Author

    Indeed, that seems to be the case. When executing:

    from __future__ import print_function
    import IPython
    def do():
        a = 42
        print("before: a={}".format(a))
        IPython.embed()
        print("after: a={}".format(a))
    do()
    

    ...changing a will not affect the output.

    I will try to fix this in the docs.

  3. olenz commented on May 22, 2014

    @olenz
    Author

    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?

  4. takluyver commented on May 23, 2014

    @takluyver
    Member

    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
    .

  5. added this to the 3.0 milestone on Oct 3, 2014
  6. modified the milestones: 4.0, 3.0 on Nov 14, 2014
  7. modified the milestones: 4.1, 4.0 on Aug 11, 2015
  8. modified the milestones: 5.0, 4.1 on Jan 19, 2016
  9. modified the milestones: 5.0, wishlist on May 2, 2016
  10. oldclesleycode commented on Nov 10, 2017

    @oldclesleycode

    working on the documentation change!

  11. jzf2101 commented on Nov 10, 2017

    @jzf2101
    Contributor

    @minrk do you mean this only to be a documentation change and not a change to the underlying behavior?

  12. minrk commented on Nov 10, 2017

    @minrk
    Member

    That’s the immediate issue, yes.

  13. modified the milestones: wishlist, 6.3 on Mar 29, 2018
  14. takluyver commented on Mar 29, 2018

    @takluyver
    Member

    Fixed by #10891

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions