Created
November 26, 2014 17:34
-
-
Save eas604/84b34cf47665cfa6ffcd to your computer and use it in GitHub Desktop.
Modified version of the function from Dive Into Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def info(obj, spacing=10, collapse=True): | |
"""Print methods and doc strings. | |
:param obj: object to inspect | |
:type obj: module or class or list or dict or str or unicode | |
:param spacing: left column width | |
:type spacing: int | |
:param collapse: whether to collapse the text when printing | |
:type collapse: bool | |
""" | |
# Modified version of the function from Dive Into Python. | |
# http://www.diveintopython.net/power_of_introspection/index.html#apihelper.divein | |
# Governed by the Python License. https://docs.python.org/2/license.html | |
assert isinstance(spacing, int) and spacing > 0 | |
method_list = [method for method in dir(obj) if callable(getattr(obj, method))] | |
process_func = collapse and (lambda s: ' '.join(s.split())) or (lambda s: s) | |
print('\n'.join(['{} {}'.format( | |
method.ljust(spacing), process_func(str(getattr(obj, method).__doc__))) for method in method_list])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment