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.
You can use dir(module) to see all available methods/attributes.
To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class.
Python gives you several different ways to view package content. The method that most developers use is to work with the dir() function, which tells you about the attributes that the package provides. Function attributes are automatically generated by Python for you.
Use the built-in dir() function to interactively explore Python modules and classes from an interpreter session. The help() built-in lets you browse through the documentation right from your interpreter.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With