How to list all functions in a Python module?

前端 未结 17 1701
野性不改
野性不改 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:09

    dir(module) is the standard way when using a script or the standard interpreter, as mentioned in most answers.

    However with an interactive python shell like IPython you can use tab-completion to get an overview of all objects defined in the module. This is much more convenient, than using a script and print to see what is defined in the module.

    • module. will show you all objects defined in the module (functions, classes and so on)
    • module.ClassX. will show you the methods and attributes of a class
    • module.function_xy? or module.ClassX.method_xy? will show you the docstring of that function / method
    • module.function_x?? or module.SomeClass.method_xy?? will show you the source code of the function / method.

提交回复
热议问题