I'm new to python and I wonder, if is possible to make a single method to manipulate with all class attributes, like:
class Test:
def __init__(self, dict1 = {"test": 0}, dict2 = {"another_test": 0}):
self.dict1= dict1
self.dict2 = dict2
def vary_attr(self, attr, key, value):
self.attr[key] += value
x = Test()
x.vary_attr('dict1', 'test', 3)
x.vary_attr('dict2', 'another_test', 6)
print(x.dict1)
# Wishful output:
# {'test': 3}
# {'another_test': 6}
Obviously, this doesn't work, but it is possible to make it work? Having one method and through that method manipulate with both attributes dict1 and dict2?!