I\'ve got a list of things, of which some can also be functions. If it is a function I would like to execute it. For this I do a type-check. This normally works for other ty
Because function isn't a built-in type, a NameError is raised. If you want to check whether something is a function, use hasattr:
function
NameError
hasattr
>>> hasattr(f, '__call__') True
Or you can use isinstance():
isinstance()
>>> from collections import Callable >>> isinstance(f, Callable) True >>> isinstance(map, Callable) True