Skip to content

Instantly share code, notes, and snippets.

@davidmoremad
Last active February 4, 2019 10:02
Show Gist options
  • Save davidmoremad/3e825489d4a66ad670b42642f7d83394 to your computer and use it in GitHub Desktop.
Save davidmoremad/3e825489d4a66ad670b42642f7d83394 to your computer and use it in GitHub Desktop.
Common snippets or tips for Python

Python - Common snippets or tips

List methods of a class

# Getting all objects from a class (except parent)
my_object = awspice.ec2
method_list = [ func[0] for func in inspect.getmembers(my_object, predicate=inspect.isroutine) if callable(getattr(my_object, func[0]))]
# Excluding private methods
methods = filter(lambda x: not x.startswith('_'), method_list)

for method in methods:
    x = getattr(my_object, method)
    print('Running method:',x.__name__)
    x()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment