How can I find the methods or attributes of an object in python?
Answer / 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 |
What are operators?
What is the python interactive console or python shell?
Do we need to call the explicit methods to destroy the memory allocated in python?
What are different methods to copy an object in python?
What is gil in python?
How you can access sessions in flask?
How will you change case for all letters in string in python?
What is a repl in python?
Which is better PHP or Python?
How we can copy an object in python?
What is the purpose of the pythonpath environment variable?
What is a panda in python?