Assuming you want to check to see if there exists a loaded function with You could try this:
try:
if hasattr(myString, '__call__'):
func = myString
elif myString in dir(__builtins__):
func = eval(myString)
else:
func = globals()[myString]
except KeyError:
#this is the fail condition
# you can use func()
The first if
is actually unnecessary if you will always guarantee that myString is actually a string and not a function object, I just added it to be safe.
In any case, if you actually plan on executing these functions, I'd tread carefully. Executing arbitrary functions can be risky business.
EDIT:
I added another line to be a bit more sure we don't actually execute code unless we want to. Also changed it so that it is a bit neater