[Python-ideas] global and nonlocal with atributes

Alexander Heger python at 2sn.net
Sun May 5 12:40:02 CEST 2013


> We're allowed to shadow builtins, and what's more, there's a way to
> explicitly call up the builtin even after it's been shadowed. If
> nothing else, it allows a measure of simplicity with common names like
> 'id' - instead of having to pick a different name, you just go right
> ahead and use the obvious one, knowing that the builtin _is_
> retrievable. With globals, yes it's possible to reference them via
> globals()["some_name"], but that looks ugly. Would the OP's proposal
> look better if, instead of "globals.x", it were "__globals__.x"?  Or
> possibly "__module__.x", that being a magic word that references your
> current module, whatever-it-may-be?

I suppose this way you could also go several levels up as well

__nonlocal__.__nonlocal__.x

-Alexander



More information about the Python-ideas mailing list