How can I call python functions using dynamic variable names? This is an example:
class test(object):
def __init__(self):
self.a, self.b, self.c = 1, 2 ,3
def __str__(self):
return "a: " + str(self.a) + \
", b: " + str(self.b) + \
", c:" + str(self.c)
def inc_a(self):
self.a += 1
t1 = test()
print(t1)
t1.inc_a() # this is what I DON'T want, individual increment functions
print(t1)
# I would like a inc that works like this:
# t1.inc(a) --> increase a by 1
# t1.inc(b) --> increase b by 1
# t1.inc(c) --> increase c by 1
# print(t1)
Thx&kind regards
t.inc(a),aneeds to be an already defined object/ variable else you'll getNameError.