Evan Kroske
Evan Kroske

Reputation: 4554

How can I list the methods in a Python 2.5 module?

I'm trying to use a Python library written in C that has no documentation of any kind. I want to use introspection to at least see what methods and classes are in the modules. Does somebody have a function or library I can use to list the functions (with argument lists) and classes (with methods and member variables) within a module?

I found this article about Python introspection, but I'm pretty sure it doesn't apply to Python 2.5. Thanks for the help.

Upvotes: 29

Views: 43493

Answers (4)

Alex Martelli
Alex Martelli

Reputation: 881487

Mark Pilgrim's chapter 4, which you mention, does actually apply just fine to Python 2.5 (and any other recent 2.* version, thanks to backwards compatibility). Mark doesn't mention help, but I see other answers do.

One key bit that nobody (including Mark;-) seems to have mentioned is inspect, an excellent module in Python's standard library that really helps with advanced introspection.

Upvotes: 12

Ned Batchelder
Ned Batchelder

Reputation: 375484

Just this is pretty good too:

import module
help(module)

It will print the docstring for the module, then list the contents of the module, printing their docstrings too.

Upvotes: 8

Alexander Ljungberg
Alexander Ljungberg

Reputation: 6362

Here are some things you can do at least:

import module

print dir(module) # Find functions of interest.

# For each function of interest:
help(module.interesting_function)
print module.interesting_function.func_defaults

Upvotes: 58

Alex Gaynor
Alex Gaynor

Reputation: 14989

The dir() functions shows all members a module has.

Upvotes: 4

Related Questions