To reference class variables , you do not need explicitly self . This is necessary for referencing objects ( class instance ). To refer to a class variable, you can simply use this class name, for example:
class C: x = 1 def set(self, x): Cx = x print Cx a = C() a.set(2) print ax print Cx
the first print will give you 1 and the other 2 . While this is possible, not what you need / need . (Class variables are bound to the class, not to the object. This means that they are shared between all instances of this class. Btw, using self.x in the above example, will mask the class variable.)
source share