Code Comments

Code Comments

Tips and short tutorials on various programming technologies

Code Comments RSS Feed
 
 
 
 

How to List All Methods in a Python Object

Suppose you have an object in Python that you retrieved from a third-party library, but you don’t have access to the source code or to very good documentation. Believe me, it happens (and did to me today). You can use a simple built-in method in Python to find out which methods are exposed by a given object: dir().

x = ... #get from somewhere
print dir(x)

One Response to “How to List All Methods in a Python Object”

  1. 1
    Navneeth:

    Hi! I’m came here (to your old blog, actually) trying to find out how to make Python find if a file exists. (os.path.exists(), to anyone who might be wondering about the same.)

    I think all these snippets will be very useful to someone like me, who is new to the language. Thanks.

Leave a Reply