class methods and variables
Robert Brewer
fumanchu at amor.org
Wed Mar 24 11:39:51 EST 2004
Niurka wrote:
> Having the class Name, is there any way to obtain the class
> methods or even the
> variables it has defined?
> Is there in python something like the Java reflection?
Start with the builtin function dir():
>>> class C(object):
... var1 = 3
... var2 = 'lifeboat'
... def mangle(self, thing):
... return thing * self.var1
...
>>> dir(C)
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__',
'mangle', 'var1', 'var2']
^^^^^^^^^^^^^^^^^^^^^^^^
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list