Created
January 10, 2023 10:18
-
-
Save cyrillkuettel/9dda065c57081275fe63516cda042381 to your computer and use it in GitHub Desktop.
Get all methods of object at runtime
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 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