I am trying to pass the name of a function into another function as an argument but I get an error: TypeError: 'str' object is not callable
. Here is a simplified example of the problem:
def doIt(a, func, y, z):
result = z
result = func(a, y, result)
return result
def dork1(arg1, arg2, arg3):
thing = (arg1 + arg2) / arg3
return thing
def dork2(arg1, arg2, arg3):
thing = arg1 + (arg2 / arg3)
return thing
When I call doIt like so:
var = 'dork1'
ned = doIt(3, var, 4, 9)
print (ned)
I get:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
ned = doIt(3, var, 4, 9)
File "<pyshell#2>", line 3, in doIt
result = func(a, y, result)
TypeError: 'str' object is not callable