Python handles globals badly.

Sven R. Kunze srkunze at
Fri Sep 4 20:05:07 CEST 2015

On 04.09.2015 18:55, tdev at wrote:
>  From knowing e.g Java as OO language I had no need to set
> such a keyword "global" to get write access to class members.

It is true and I really dislike Java for having this. Please consider this

class MyClass:
     def method(cls):attribute = 'a'         cls.myattribute = 1234

As you see, even when using a class for the purpose, you still need to 
reference the class object somehow.

> And now the main point: Cause all of the features and especially
> the singleton construct, I could not believe that Python
> does nearly all for me but forces me then to use such
> a "ugly" keyword "global" in comparison to other OO languages.

It is ugly, that is true. Would something like this help you?

def method(mod):
     attribute = 'a'
     mod.myattribute = 123

Works like classmethod but on module level. You still need to explicitly 
specify from which namespace you want myattribute but that's the Python 
way I think. It applies to instance methods, class methods and all other 
types of Python code.

> But I agree, I should have better never mentioned it.
> Please lay  OO and sharing globals aside.
> It is really about procedural programming and "global"-keyword only.
> That said I will really give no longer any comments about this.

That is sad. :(
I at least would like to know if my suggestion would help? :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list