Get Available Functions

Tim Chase python.list at tim.thechases.com
Mon Jan 28 12:01:46 EST 2008


> I'm working with a python module which isn't part of the core
> Python API and it also isn't very documented or supported, is
> there any way that I can easily dump/view the available
> classes and methods within the package from within python?

Most of the time, the dir(), type() and help() functions can be 
your friend:

 >>> import somelib
 >>> dir(somelib)
['Foo', 'thing', 'whatever']
 >>> type(somelib.Foo)
<type 'Foo'>
 >>> dir(somelib.Foo)
['method1', 'method2']
 >>> type(somelib.thing)
<type 'str'>
 >>> print somelib.thing
'I didn't expect the Spanish Inquisition!'
 >>> type(somelib.whatever)
<type 'function'>
 >>> help(somelib.whatever)
Help on function whatever in module somelib:

whatever(param1, param2, *args, **kwargs)
 >>>


I've had a couple cases where the underlying module was written 
in C (mod_python in particular...don't know if it still has this 
problem) where dir() wouldn't actually tell you about the object, 
but for most cases, dir() will get you pointed in the right 
dir-ection. :)

-tkc






More information about the Python-list mailing list