On Sat, Apr 3, 2010 at 6:31 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > Steve Bonner wrote: >> What do we think of adding a built-in nonlocals() function that would >> be similar to globals() and locals()? Like those functions, it would >> return a dictionary of variable names and their values. Since we now >> have the nonlocal statement, it would be consistent to keep the >> three scopes local/nonlocal/global with parallel capabilities. And it >> might sometimes be useful for code inside a nested function to see >> what variables are available at the enclosing level. > > That isn't as easy as it may sound. locals() and globals() are each > single namespaces, while the nonlocals may actually span multiple > namespaces.
This is probably is way off, but why not use sets. It seems that these special "functions" (which actually don't do any transformations) should be properties or attributes, and in any case would be better served by returning (holding) sets, then one could do standard set operations on them (including the set difference operations upon the set named "locals"). These old functions predate the introductions of attributes/properties and sets, and like anything that is sure to be a group containing no duplicates, it should really return a set to remove the ambiguity to the programmer (unlike returning a list as is presently). That includes dir() too and probably others. python3k-to-you-toly yours, marcos _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com