equivalent to globals(), locals() for nonlocal variables?

Discussion in 'Python' started by geremy condra, Oct 21, 2009.

  1. I decided to play around with nonlocal declarations today, and was
    somewhat surprised when a call to nonlocals() resulted in 'nonlocals
    is not defined'. Is there an a standard equivalent to globals() or
    locals() for variables in outer nested scopes?

    Geremy Condra
     
    geremy condra, Oct 21, 2009
    #1
    1. Advertising

  2. geremy condra

    Lie Ryan Guest

    geremy condra wrote:
    > I decided to play around with nonlocal declarations today, and was
    > somewhat surprised when a call to nonlocals() resulted in 'nonlocals
    > is not defined'. Is there an a standard equivalent to globals() or
    > locals() for variables in outer nested scopes?
    >
    > Geremy Condra


    Not that I know of, but you can, to certain extent, do something like this:

    def outer():
    def inner():
    print nonlocals
    nonlocals = locals()
    inner()
    outer()
     
    Lie Ryan, Oct 22, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Giles Brown

    Question about "exec in globals, locals"

    Giles Brown, Jul 4, 2003, in forum: Python
    Replies:
    2
    Views:
    382
    Adrien Di Mascio
    Jul 4, 2003
  2. tedsuzman
    Replies:
    2
    Views:
    7,166
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  3. Ted
    Replies:
    1
    Views:
    497
    Duncan Booth
    Jul 22, 2004
  4. Olivier Sessink
    Replies:
    0
    Views:
    416
    Olivier Sessink
    Feb 24, 2005
  5. Faisal Alquaddoomi

    Globals, Locals Dictionaries + Callbacks Question

    Faisal Alquaddoomi, Dec 21, 2005, in forum: Python
    Replies:
    3
    Views:
    387
    Steve Holden
    Dec 22, 2005
Loading...

Share This Page