Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def find_method(module,searchstr,print_doc=True):
  2.   """
  3.  Returns a list of methods inside 'module' which contain 'searchstr' in their docstring
  4.  
  5.  Input: Module name and and string to search for, optionally prints the help for the methods (default=True)
  6.  Output: List of methods
  7.  """
  8.   methods = []
  9.   for submod_name in dir(module):
  10.     submod = module.__getattribute__(submod_name)
  11.     if submod.__doc__ and searchstr in submod.__doc__:
  12.       methods += [submod]
  13.  
  14.   # print output
  15.   if print_doc:
  16.     print "%d methods founds. Show their help? [Y/n]"%(len(methods))
  17.     inp = raw_input()
  18.     if not inp or inp.lower() == "y":
  19.       for method in methods:
  20.         help(method)
  21.   return methods
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement