Computer >> Computer tutorials >  >> Programming >> Python

How do I get list of methods in a Python class?


The following code prints the list of methods of the given class as follows

Example

class foo:
    def __init__(self):
        self.x = x
    def bar(self):
        pass
    def baz(self):
        pass
print (type(foo))
import inspect
print(inspect.getmembers(foo, predicate=inspect.ismethod))

Output

The output is 

<type 'classobj'>
[('__init__', <unbound method foo.__init__>), ('bar', <unbound method foo.bar>), ('baz', <unbound method foo.baz>)]