How do I enumerate functions of a Python class?


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

  

 

Updated on: 15-Jun-2020

146 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements