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

Lie Ryan lie.1296 at gmail.com
Thu Oct 22 15:37:25 CEST 2009


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()



More information about the Python-list mailing list