Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have a python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it.

I want to call the doc function on each one. In ruby, I can do something like ClassName.methods to get a list of all the methods available in that class. Is there something similar in python?

eg. something like:

from somemodule import foo

print foo.methods # or whatever is the correct method to call

1 Answer

0 votes
by (106k points)

To list all functions in a Python module you can use dir(module).

You can also use the inspect module, it will also list all the functions in a Python module. Below is the code for the same:-

from inspect import getmembers, isfunction

from my_project import my_module

functions_list = [o for o in getmembers(my_module)if isfunction(o[1])]

Related questions

0 votes
4 answers
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.6k points)

Browse Categories

...