Take a look at this question.
In a nutshell, your class and your class instance have different namespaces (Actually, this is not very correct because instance namespace kinda places on top of class' namespace so that in case if you have a class atribute and an instance attribute with the same name, instance' one will be accessed through inst.attr
, otherways - class' one). So, when you do
object1.variable = 1
you do not actually change class variable (which is often called static field in other languages), you just bind a new field called variable
to your class instance object1
.
What you probably want to do is to change class variable, not instance one. It could be done like this:
Sample.variable = 1
or like this:
object1.__class__.variable = 1