Something like java's reflection???

holger krekel pyth at devel.trillke.net
Tue Aug 27 16:18:43 EDT 2002


Frank Buss wrote:
> "KC" <khcarlso at bellsouth.net> wrote:
> 
> > I am curious if there is a way to get information at run time on an
> > objects internal attributes and methods -- something similar to java's
> > reflection api.  Is this possible in Python?
> 
> Yes, you can use __dict__ on the class object and on instances. Example 
> Python interactive session:

True but there is a nice module which handles some common usages.
It's called 'inspect' and somewhat resembles the java-API.

>>> import inspect
>>> help(inspect)
Help on module inspect:

NAME
    inspect - Get useful information from live Python objects.

FILE
    /usr/lib/python2.2/inspect.py

DESCRIPTION
    This module encapsulates the interface provided by the internal
special
    attributes (func_*, co_*, im_*, tb_*, etc.) in a friendlier fashion.
    It also provides some help for examining source code and class
    layout.

[...]

HTH,

    holger




More information about the Python-list mailing list