How to list all functions in a Python module?

前端 未结 17 1693
野性不改
野性不改 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条回答
  •  终归单人心
    2020-11-22 06:14

    For code that you do not wish to parse, I recommend the AST-based approach of @csl above.

    For everything else, the inspect module is correct:

    import inspect
    
    import  as module
    
    functions = inspect.getmembers(module, inspect.isfunction)
    

    This gives a list of 2-tuples in the form [(, ), ...].

    The simple answer above is hinted at in various responses and comments, but not called out explicitly.

提交回复
热议问题