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

G

geremy condra

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
 
L

Lie Ryan

geremy said:
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()
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top