I wish to create a list that hold other value in a class and make sure that list is up to date without having to update it myself.
I have tried to write it this way:
class Test:
def __init__(self, arg, arg2):
self.arg = arg
self.arg2= arg2
self.list = [self.arg, self.arg2] #list I want up to date
def update(self, arg, arg2):
self.arg = arg
self.arg2 = arg2
#the simple answer is to add: self.list=[self.arg, self.arg2] or a function doing it. That is not what I am asking.
def write_list(self):
print(self.list)
tes = Test(1, 2)
tes.write_list()
tes.update(23,24)
tes.write_list()
I want the output to be:
[1,2]
[23,24]