Skip to content

Instantly share code, notes, and snippets.

@dvanic
Created October 15, 2019 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvanic/93b1259b56ef9212418458fb66331d72 to your computer and use it in GitHub Desktop.
Save dvanic/93b1259b56ef9212418458fb66331d72 to your computer and use it in GitHub Desktop.
pythonGetObjectMethod
def get_methods(object, spacing=20):
methodList = []
for method_name in dir(object):
try:
if callable(getattr(object, method_name)):
methodList.append(str(method_name))
except:
methodList.append(str(method_name))
processFunc = (lambda s: ' '.join(s.split())) or (lambda s: s)
for method in methodList:
try:
print(str(method.ljust(spacing)) + ' ' +
processFunc(str(getattr(object, method).__doc__)[0:90]))
except:
print(method.ljust(spacing) + ' ' + ' getattr() failed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment