I am trying to call a variable defined in a function, inside another function of the same class, but with self doesn't work.
class Project():
def function1(self):
a='hello world,'
def function2(self):
b=self.a + ' I am alive'
Project1=Project()
print Project1.function1()
print Project1.function2()
python says: Project instance has no attribute 'a'.
I don't know very well how to use classes. I didn't use __init__ 'cause I do not have anything to put, is there maybe a way to add it even if I do not need it formally?
Thanks for your help.
function1,ais local. You probably wantedself.a='hello world, 'self.a(attributeaof the objectself) is never defined.ainfunction1is local variable. See Classes - Python Scopes and Namespaces.