printing class methods

Jason Orendorff jason at
Fri Jan 25 00:28:36 EST 2002

Joe wrote:
> sorry, just as I saw my mail disappear I remebered -
> dir(class_or_module_name), but the second question still stands - Is there
> a way to find out the number and type of arguments?

Arguments aren't typed.

The "inspect" module will help you find the number and names
of arguments.

Sample usage:

import inspect

for name in dir(MyClass):
    method = getattr(MyClass, name)
    if callable(method):
        # methods aren't exactly the same thing as functions,
        # so you get a method, you have to grab it's "im_func"
        # attribute to get at the underlying function.
            method = method.im_func
        except AttributeError:
        print name, inspect.getargspec(method)

## Jason Orendorff

More information about the Python-list mailing list