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

PythonServer Side ProgrammingProgramming

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>)]

raja
Published on 24-Jan-2018 18:15:59
Advertisements