Larz60+ Wrote:You should make a case and pep to suggest it be removed from the language.It absolutely should not be removed from the language, but this isn't a good use case for it. This argument is just as valid as asking why I don't write a pep to remove eval/exec. They serve a purpose; this isn't it.
One of the main reasons to use it is to define constants within a function. And after definition to not change them. Say you are programatically building up a large dictionary which you want to be a global constant but don't want any other variables needed in the building process defined globally. Even then you could just return and assign. It is almost never the right thing to do, and in code of new programmers I have NEVER seen a single case where it was.
The fact that the OP had already committed towards doing the wrong thing is even more a reason to try to correct them.
I actually do use the
global
keyword as can be seen here: https://github.com/Mekire/pygame-samples...im.py#L217
The use in this situation is some preprocessing on an object that both can't be created until another module is initialized and requires a conversion in order to use efficiently. Not using the
global
keyword would mean I needed to init the module in the global namespace which I stylistically don't like. It is also defined in caps to indicate it is indeed to be treated as a constant.