How to list all functions in a Python module?

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

    The Python documentation provides the perfect solution for this which uses the built-in function dir.

    You can just use dir(module_name) and then it will return a list of the functions within that module.

    For example, dir(time) will return

    ['_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic', 'monotonic_ns', 'perf_counter', 'perf_counter_ns', 'process_time', 'process_time_ns', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'time_ns', 'timezone', 'tzname', 'tzset']

    which is the list of functions the 'time' module contains.

提交回复
热议问题