Look at the question .
In short, your class and your class instance have different namespaces (in fact, this is not very correct, because the namespace of the instance instances is placed on top of the class namespace, so if you have a class attribute and an instance attribute with the same name, instance 'one will be available through inst.attr , otherways - class' one). So, when you do
object1.variable = 1
you donβt actually change the class variable (which is often called a static field in other languages), you simply bind a new field called variable with an instance of class object1 .
What you probably want to do is change the class variable, not instance 1. This can be done as follows:
Sample.variable = 1
or like this:
object1.__class__.variable = 1
source share