With the inspect and importlib library, we can get all functions in a .py file.
import importlib
import inspect
my_mod = importlib.import_module("mymod")
all_functions = inspect.getmembers(my_mod, inspect.isfunction)
However, the list all_functions
includes not only functions defined in the module, but also functions imported to the module.
Is there a way to distinguish them?