oop - Is there a way to print a short version of the docstring for all members of a Python object? -
in python dir() returns list of names in current local scope. __doc__ returns complete docstring of object.
how can list names in current local scope , print first line of each item's docstring ?
to elaborate: import numpy np list of short descriptions of names returned dir(np) e.g. print(np.nonzero.__doc__.split('.', 1)[0]).
how can ?
def print_members(obj): key in dir(obj): value = getattr(obj, key) doc = (value.__doc__ or '').split('.', 1)[0] print('member: %s\ndocstring: %s\n\n' % (key, doc))
Comments
Post a Comment