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: 2020-06-15T11:58:49+05:30

207 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements