On 05/12/2015 03:58 PM, zljubisic...@gmail.com wrote:
On Tuesday, May 12, 2015 at 9:49:20 PM UTC+2, Ned Batchelder wrote:
If you need to use globals, assign them inside a parse_arguments
function that has a "global" statement in it.
This advice is consistent with Chris' "define things before they
are used." It does it by defining everything before anything is
run.
As a side note, if you are going to have code at the top-level of
the file, then there's no point in the "if __name__..." clause.
That clause is designed to make a file both runnable and importable.
But your top-level code makes the file very difficult to import.
--Ned.
It makes sense. The only drawback is that variables are global
only "if you need to use globals". You can't have it both ways. If
they're needed, it's because you feel they must be changeable elsewhere
in the program. I try to avoid global variables, but make no such
restraints on the use of global constants. So for example, the argument
parsing logic could very well export something as global, but it'd be
all uppercase and anyone changing it subsequently would get their hand
slapped by the linter.
so they could be changed anywhere in the program.
I also agree that it is more python approach.
Thanks to both of you.
--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list