How can I find the methods or attributes of an object in python?

Answer Posted / chaitanya

Built-in dir() function of Python ,on an instance shows the instance variables as well as the methods and class attributes defined by the instance's class and all its base classes alphabetically. So by any object as argument to dir() we can find all the methods & attributes of the object’s class.

Following code snippet shows dir() at work :

class Employee:

def __init__(self,name,empCode,pay):

self.name=name

self.empCode=empCode

self.pay=pay

print("dir() listing all the Methods & attributes of class Employee")

print dir(e)

-----------------------------------------------------

Output

dir() listing all the Methods & attributes of class Employee

[ '__init__', 'empCode', 'name', 'pay']

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does map function in python do?

501


How do I copy a file?

521


What's the difference between python and anaconda programming?

440


How do I use python idle?

457


What is numpy shape?

447






What is python and why python?

442


Where do you use python programming? Can you describe in detail?

471


How many hours learn python?

454


Does Python support strongly for regular expressions?

521


Mention the use of the split function in Python?

488


Explain list, tuple, set, and dictionary and provide at least one instance where each of these collection types can be used.

525


What does stringvar.strip() does?

538


How does python input work?

468


How to share global variables across modules?

445


What is the use of python interpreter?

394