Skip to content

Instantly share code, notes, and snippets.

@cyrillkuettel
Created January 10, 2023 10:18
Show Gist options
  • Save cyrillkuettel/9dda065c57081275fe63516cda042381 to your computer and use it in GitHub Desktop.
Save cyrillkuettel/9dda065c57081275fe63516cda042381 to your computer and use it in GitHub Desktop.
Get all methods of object at runtime
def get_methods(object, spacing=20):
""" Convenience method to print all methods at runtime. """
method_list = []
for method_name in dir(object):
try:
if callable(getattr(object, method_name)):
method_list.append(str(method_name))
except Exception:
method_list.append(str(method_name))
process_func = (lambda s: ' '.join(s.split())) or (lambda s: s)
for method in method_list:
try:
print(str(method.ljust(spacing)) + ' ' +
process_func(str(getattr(object, method).__doc__)[0:90]))
except Exception:
print(method.ljust(spacing) + ' ' + ' getattr() failed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment