Is there a method to find all functions that were defined in a python environment?
For instance, if I had
def test:
pass
some_command_here
would return test
We can list down all the functions present in a Python module by simply using the dir() method in the Python shell or in the command prompt shell.
The dir() function The dir() built-in function returns a sorted list of strings containing the names defined by a module. The list contains the names of all the modules, variables, and functions that are defined in a module.
In this tutorial you will learn user defined functions in Python with the help of examples. In the last tutorial of Python functions, we discussed that there are two types of functions in Python: Built-in functions and user defined functions.
You can use inspect module:
import inspect
import sys
def test():
pass
functions = [name for name, obj in inspect.getmembers(sys.modules[__name__], inspect.isfunction)]
print functions
prints:
['test']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With