Python handles globals badly.

MRAB python at mrabarnett.plus.com
Fri Sep 11 19:03:54 EDT 2015


On 2015-09-11 22:26, tdev at freenet.de wrote:
> Reflecting latest answers to global and "proposals"
>
[snip]

> But you can say, the "general" sample is:
> You have to specify global that the compiler can distinguish
> between local and global
> Other words: global is needed to distinct global from local.
>
> But this is "not" true.
> You specify global cause you want write access.
> Even the rules specified proves it:
>
>> 1) If it's in the function's argument list, it's an argument (and
>> therefore local).
>> 2) If it's explicitly declared global, then it's global.
>> 3) If it's never assigned within the function, then it's global.
>> 4) Otherwise, it's local.
>
> Take step 2 out than it is again recognized as global.
> So the global keyword is not needed to distinguish global from local.
> Rule 3 proves it.
>
I'd would rephrase 3 and 4:

1) If it's in the function's argument list, it's local.

2) If it's declared global, it's global.

3) If it's assigned within the function, it's local.

4) Otherwise, it's global.

>
> Conclusion.
> I will use Python, but never become a Pythonier,
> although quite conform with its philosophy "One best way".
> But even a traditional switch is denied, although much clearer
> in reading and writing than any if-else construct.
> I can and will not understand it.
>
No-one can decide on how it should be written without it looking
syntactically inconsistent in some way compared to the other control 
structures.

>
> Thanks for your answers.
>
>




More information about the Python-list mailing list