Python handles globals badly.
antoon.pardon at rece.vub.ac.be
Tue Sep 8 11:07:27 CEST 2015
Op 04-09-15 om 04:33 schreef Steven D'Aprano:
> On Fri, 4 Sep 2015 05:05 am, tdev at freenet.de wrote:
>> Would you remove this keyword if it would be technically possible
> Absolutely not.
> I do not believe that it is technically possible, but even if it were, I
> would still argue that the Zen of Python applies:
> Explicit is better than implicit.
> Local variables should be the default, and you should explicitly declare any
> time you want to write to a global.
> Not the other way around, like Lua does. I've always thought that was silly:
> you should make the *desirable* thing easy to do, and the *dangerous* think
> (using globals) possible but not easy to do by accident.
You are trying to have your cake and eat it. If explicit is better than implicit
then declaring your variable at the scope it has to live in, is what you need
to do, that is the explicit way.
Not needing to declare local variables, is an implicit way, since it is behaviour
depending on something not being indicated.
More information about the Python-list