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
Explain about exceptions in python?
How do you invoke the python interpreter for interactive use?
What is py checker in python?
What does the list comprehension do?
When do you choose a list over a tuple?
What is the length of your largest python code? Can you please describe the project?
Why you should learn python in 2019?
What do you understand by python modules?
What happens if we do not handle an error in the except block?
Do python functions need return?
What are identifiers python?
Is python faster than c#?
which is the most commonly used package for data importing and manipulation?
What is the best python interpreter?
Who built the sphinx?