[Python-ideas] global and nonlocal with atributes

João Bernardo jbvsmo at gmail.com
Sun May 5 17:44:23 CEST 2013


(posting to the list)


> Whenever there's an assignment inside a big function,
>>
>
> If a function is 'too big', it can be split. Nexted functions that rebind
> a nonlocal name (closures), which is more often sensible than rebinding
> global names, are and should usually be short enough already.
>
> Programming is also about reading other people's ugly code.


 So, I why not have attribute syntax on "global" and "nonlocal" keywords?
>>
>
> Because attributes are attributes of objects and keywords are not objects
>
>
Read again the part where I said:  'so "global" and "nonlocal" will not be
objects'.
BTW, Some other keywords do multiple jobs, like "if/else", "yield" and
"super".
Somehow, "super" is not in the list of python keywords, but it alters the
environment where it is inserted in a way that no other variable can.
Try doing "mega = super" and initialize a class with "mega().__init__()".

I still think "global" an "nonlocal" shouldn't become objects, thought.

One can already do something similar
> g = globals()
> ...
> g['x'] += 1
>
>
This won't work with "locals".
Also, there's not a way to access "nonlocal" variables.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130505/e82a5cd4/attachment.html>


More information about the Python-ideas mailing list