Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 is instance of a class?

988


What's a python script?

902


Explain the //, %, and ** operators in python?

897


How do you sort a dataframe in python?

892


Can you run python programs without python installed?

862


Why does comparing strings in python using either β€˜==’ or β€˜is’ sometimes produce a different result?

772


How can you create a gui based application in python for client-side functionality?

842


Which is fastest implementation of python?

925


Is nodejs faster than python?

815


What is pydoc command?

834


What is r regex?

826


Explain python list comprehension?

846


Why lambda forms in python does not have statements?

1016


What is shebang python?

829


Name few python web application frameworks?

898