[Python-ideas] A "local" pseudo-function

Ethan Furman ethan at stoneleaf.us
Sun Apr 29 21:20:33 EDT 2018


On 04/29/2018 01:20 PM, Tim Peters wrote:

> So, e.g.,
>
> """
> a = 42
>
> def showa():
>      print(a)
>
> def run():
>      global a
>
>      local a: # assuming this existed
>          a = 43
>          showa()
>      showa()
> """
>
> would print 43 and then 42.  Which makes "local a:" sound senseless on
> the face of it ;-)  "shadow" would be a more descriptive name for what
> it actually does.

Yeah, "shadow" would be a better name than "local", considering that it effectively temporarily changes what other 
functions see as global.  Talk about a debugging nightmare!  ;)

--
~Ethan~


More information about the Python-ideas mailing list