Oct-18-2020, 10:41 PM
Hi,
as an almost beginner, this is just a general knowledge question.
Let's say i have a class foo defining method1, method2, method3.
I'd like to have a function outside class foo, for example:
my_function(fooinstance,name,num),
and build the fooinstance method name by name+num, and then call fooinstance.(name+num).
I'd like to avoid bunch of tests of the kind:
if name==method and num==1: fooinstance.method1()
Is such behavior possible ? Otherwise, gotta code those 40 if..elif i want to avoid.
thanks
as an almost beginner, this is just a general knowledge question.
Let's say i have a class foo defining method1, method2, method3.
I'd like to have a function outside class foo, for example:
my_function(fooinstance,name,num),
and build the fooinstance method name by name+num, and then call fooinstance.(name+num).
I'd like to avoid bunch of tests of the kind:
if name==method and num==1: fooinstance.method1()
Is such behavior possible ? Otherwise, gotta code those 40 if..elif i want to avoid.
thanks