Given the class:
class MyClass:
def __init__(self):
self.log = []
return
def fitness(self, x):
return x*x
I want to be able to store into the log
attribute, the output to each call of the fitness
method. In order to have the following:
my_obj = MyClass()
my_obj.fitness(3)
# Expected output 9
my_obj.fitness(6)
# Expected output 36
my_obj.log
# Expected output [9, 36]
I was thinking about a method decorator, but I don't know how to pass the attribute as argument. I need the log attribute to be embedded in the class and not an external variable. I am using python 3.