How to list all functions in a Python module?

前端 未结 17 2067
野性不改
野性不改 2020-11-22 05:38

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

17条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 06:09

    An example with inspect:

    from inspect import getmembers, isfunction
    from my_project import my_module
    
    functions_list = [o for o in getmembers(my_module) if isfunction(o[1])]
    

    getmembers returns a list of (object_name, object_type) tuples.

    You can replace isfunction with any of the other isXXX functions in the inspect module.

提交回复
热议问题