A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-April/099075.html below:

[Python-Dev] nonlocals() function?

[Python-Dev] nonlocals() function? [Python-Dev] nonlocals() function?Antoine Pitrou solipsis at pitrou.net
Mon Apr 5 14:17:27 CEST 2010
Steve Bonner <pythonsteve <at> gmail.com> writes:
> 
> 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.

These scopes don't have parallel capabilities:

>>> def f():
...   x = 5
...   locals()['x'] = 6
...   return x
... 
>>> f()
5

> And it
> might sometimes be useful for code inside a nested function to see
> what variables are available at the enclosing level.

"It might sometimes be useful" translates in my head to "I've never seen an
actual use case for this".

-1 on an useless complication of the interpreter.


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4