I am trying to access an updated initialized variable by a python method to another python method in same class. Below is my sample code block.
class test(object):
def __init__(self):
self.a = []
def test1(self):
self.a = [1,2,3,4,5]
print ("Output of test1 #", self.a)
def test2(self):
print ("Output of test2 #",self.a)
test().test1()
test().test2()
Output # Output of test1 # [1, 2, 3, 4, 5]
Output of test2 # []
My understanding is if i Initialize a variable in __ init __(self) section then i can update the same variable from a method in the class and access the same variable from another method of same class. Correct me if my understanding is wrong.
test. Instead:t = test(); t.test1(); t.test2()does what you want. You may want up a bit more on (Python) classes.