Sep-10-2018, 10:06 AM
I'm trying to work out how to test for an object being a function. Can you help?

def my_func(): print("Running my function...") # my_func() random_func =my_func # Print the type of object. print(type(random_func)) # _. # Return true or false to the question. print("Is this a function?", isinstance(random_func, function)) # _. # Run the function. random_func()
Error:<class 'function'>
Traceback (most recent call last):
File "/home/pi/Documents/Alan/Python/Test/function type.py", line 16, in <module>
print("Is this a function?", isinstance(random_func, function))
NameError: name 'function' is not defined
>>>