I have a number of functions called func_1
, func_2
, ... I'd like to call each of them in a for
loop.
I could do:
for f in [func_1, func_2, func_3]:
print f('foo', 'bar')
but I'd like less typing. Is there any way to generate the names, something like:
for f in ['func_%s' % range(1,5)]:
print f('foo', 'bar')
This fails with 'str' object is not callable
, but is there anything like this that works?
EDIT: I'm testing a number of alternative versions of func
. They are all supposed to give the same result, but with different implementations. I control the inputs and this is not in production.
However, this is bad and possibly dangerous practice in other contexts. See the comments and answers.