Most viewed recipes tagged "nonlocal"http://code.activestate.com/recipes/tags/nonlocal/views/2015-09-08T01:27:04-07:00ActiveState Code RecipesNested contexts -- a chain of mapping objects (Python) 2010-10-25T02:13:37-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/577434-nested-contexts-a-chain-of-mapping-objects/ <p style="color: grey"> Python recipe 577434 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/ast/">ast</a>, <a href="/recipes/tags/chained/">chained</a>, <a href="/recipes/tags/compiler/">compiler</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/inheritance/">inheritance</a>, <a href="/recipes/tags/nested/">nested</a>, <a href="/recipes/tags/nonlocal/">nonlocal</a>, <a href="/recipes/tags/scopes/">scopes</a>, <a href="/recipes/tags/xml/">xml</a>). Revision 2. </p> <p>Easy to use chain of dictionaries for crafting nested scopes or for a tree of scopes. Useful for analyzing AST nodes, XML nodes or other structures with multiple scopes. Can emulate various chaining styles including static/lexical scoping, dynamic scoping and Python's own globals(), locals(), nested scopes, and writeable nonlocals. Can also model Python's inheritance chains: instance dictionary, class dictionary, and base classes.</p> Python 2 nonlocal (Python) 2015-09-08T01:27:04-07:00Ryan Gonzalezhttp://code.activestate.com/recipes/users/4187447/http://code.activestate.com/recipes/578965-python-2-nonlocal/ <p style="color: grey"> Python recipe 578965 by <a href="/recipes/users/4187447/">Ryan Gonzalez</a> (<a href="/recipes/tags/backport/">backport</a>, <a href="/recipes/tags/nonlocal/">nonlocal</a>, <a href="/recipes/tags/python2/">python2</a>). Revision 2. </p> <p>This implements nonlocal in Python 2...albeit in a slightly ugly way. Tested with CPython 2.7 and PyPy.</p>