Your operator is try
incorrect. It should have been -
def testFunction(entity):
try: return callable(eval(entity))
except NameError:
return False
You also do not need to call a function (to check its presence or not). Above, the built-in function callable
is used to check if a entity
function / class or so.
( , module.function
), , globals()
, eval()
. -
def testFunction(entity):
try: return callable(globals()[entity])
except KeyError:
return False
, True
, - module.function
.. , , entity
, eval
.