How do I enumerate functions of a Python class?

PythonServer Side ProgrammingProgramming

The following code prints the list of functions 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 22-Jan-2018 13:18:22
Advertisements