class MyClass:
var1 = 1
def update(value):
MyClass.var1 += value
def __init__(self,value):
self.value = value
MyClass.update(value)
You are confusing classes and instances.
class MyClass(object):
pass
a = MyClass()
MyClass
is a class, a
is an instance of that class. Your error here is that update
is an instance method. To call it from __init__
, use either:
self.update(value)
or
MyClass.update(self, value)
Alternatively, make update
a class method:
@classmethod
def update(cls, value):
cls.var1 += value