-1

How can I find each of the functions of an imported module? For example, I got a few module names, but I cannot see what each of their functions is:

>>> help('modules')
      

Please wait a moment while I gather a list of all available modules...

__future__          brain_namedtuple_enum hjson               redirector
__main__            brain_nose          hmac                replace
_abc                brain_numpy_core_fromnumeric html                reprlib
_ast                brain_numpy_core_function_base html2text           requestlogger
_asyncio            brain_numpy_core_multiarray http                requests
_bisect             brain_numpy_core_numeric httplib2            requests_oauthlib
_blake2             brain_numpy_core_numerictypes hyperparser         rlcompleter
_bootlocale         brain_numpy_core_umath idle                rpc
_bz2                brain_numpy_ndarray idle_test           rsa
_cffi_backend       brain_numpy_random_mtrand idlelib             rstrip
_codecs             brain_numpy_utils   idna                run
pigrammer
  • 2,603
  • 1
  • 11
  • 24
david y
  • 21
  • 1
  • 3
  • 4
    Read the documentation of the modules you're importing. – Barmar Aug 28 '22 at 02:47
  • At the end it says "Enter any module name to get more help.". So, pick some module such as `re` and do `import re; help(re)`. Some modules will have doc, others not. A good source for everything in the standard libs is at https://docs.python.org. For external modules, you may find good help in the module, you may need to find the documentation on some other site. Or, the docs may be horrible or non-existent. – tdelaney Aug 28 '22 at 02:53

1 Answers1

1

One way you can accomplish this by printing out all of the methods on the object. For example,

>>> import requests
>>> method_list = [func for func in dir(requests) if callable(getattr(requests, func))]
>>> method_list
['ConnectTimeout', 'ConnectionError', 'DependencyWarning', 'FileModeWarning', 'HTTPError', 'JSONDecodeError', 'NullHandler', 'PreparedRequest', 'ReadTimeout', 'Request', 'RequestException', 'RequestsDependencyWarning', 'Response', 'Session', 'Timeout', 'TooManyRedirects', 'URLRequired', '_check_cryptography', 'check_compatibility', 'delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'request', 'session']

(Source of inspiration: https://stackoverflow.com/a/39061905/5437264) As we can see, this requests module has 28 callable methods.

This accomplishes what you ask, literally, through programmatic means. But I am not sure if it best accomplishes what you truly seek. If you want to know all of the "commands" of a module — and by this I assume you mean callable methods — for reference purposes then it would be better to take up @Barmar's advice and simply read the official documentation of the module you are using. It's really best to only call methods that the official documentation advises you call instead of snooping around and potentially calling private methods that are not intended to be called directly.

ONMNZ
  • 322
  • 3
  • 8