tags:

views:

3950

answers:

5

I'm not a pythonista, so I'm not sure if this is really obvious or not. I have a python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it so I can call the doc function on each one. In ruby I can do something like ClassName.methods to get a list of all the methods available on that class. Is there something similar in python?

eg. something like:

from somemodule import foo
print foo.methods # or whatever is the correct method to call
+19  A: 

You can use dir(module) to see all available methods/attributes. Also check out PyDocs.

camflan
+3  A: 

The inspect module. Also see the 'pydoc' module, the 'help()' function in the interactive interpreter and the 'pydoc' command-line tool which generate the documentation you are after. You can just give them the class you wish to see the documentation of. They can also generate, for instance, HTML output and write it to disk.

Thomas Wouters
+2  A: 
import types
import yourmodule

print [yourmodule.__dict__.get(a) for a in dir(yourmodule)
  if isinstance(yourmodule.__dict__.get(a), types.FunctionType)]
Oli
For this route, use getattr(yourmodule, a, None) instead of yourmodule.__dict__.get(a)
Thomas Wouters
Only shows functions, not classes, etc.
kigurai
+9  A: 

Once you've imported the module, you can just do:

 help(modulename)

... To get the docs on all the functions at once, interactively. Or you can use:

 dir(modulename)

... To simply list the names of all the functions and variables defined in the module.

Dan
+2  A: 

This will do the trick:

Dir(module)

However, if you find it annoying to read the returned list, just use the following loop to get one name per line.

for i in dir(module): print i
Algorias