Something like java's reflection???
Frank Buss
fb at frank-buss.de
Tue Aug 27 12:33:03 EDT 2002
"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:
>>> class t:
... def hello(self):
... self.data1 = "hello"
...
>>> x = t()
>>> x.__dict__
{}
>>> t.__dict__
{'__doc__': None, '__module__': '__main__', 'hello': <function hello at
80e5df0>}
>>> x.hello()
>>> x.__dict__
{'data1': 'hello'}
--
Frank Buß, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
More information about the Python-list
mailing list