snippets

🔌 Toolbox of short, reusable pieces of code and knowledge.

View the Project on GitHub rosikand/snippets

Print methods of object/class

  1. Create an instance of a class (e.g. my_obj).
  2. Use the dir method:
    print(dir(my_obj))
    

Note that this will print out all of the dunder methods as well. To filter those out, use (this snippet was taken from here):

method_list = [method for method in dir(MyClass) if method.startswith('__') is False]
print(method_list)

Alternatively, use the inspect package:

import inspect 

 # Store methods in a list 
method_list = inspect.getmembers(ClasName, predicate=inspect.ismethod)
 
print(method_list)

See more here.