Related questions
Updating Class variable within a instance method
class MyClass:
var1 = 1
def update(value):
MyClass.var1 += value
def __init__(self,value):
self.value = value
MyClass.update(value)
a = MyClass(1)
I'm trying to update a class variable(var1) within a method(_init_) but I gives me:
TypeError: unbound method …
Accessing a class' member variables in Python?
class Example(object):
def the_example(self):
itsProblem = "problem"
theExample = Example()
print(theExample.itsProblem)
How do I access a class's variable? I've tried adding this definition:
def return_itsProblem(self):
return itsProblem
Yet, that fails also.