Saturday, May 22, 2010

Create a dynamic class in python and then use introspection to evalute each member of that class

>>> class Test():
...     pass
...
>>> a = Test()
>>> a.blah = 5
>>> dir(a)
['__doc__', '__module__', 'blah']
>>> for x in dir(a):
...     if "__" not in x:
...             print eval("a." +str(x))
...
5

No comments: