Traversing the properties of a Class

Daniel Nogradi nogradi at gmail.com
Thu Jan 18 19:56:05 CET 2007


> I'm using Python version 2.4 and I created a class with some properties
> like:
>
> def GetCallAmount(self):
>         return somedata
>
> def GetCallCurrency(self):
>     return  somemoredata
>
> more....defs..etc.
>
> CallAmount           = property(GetCallAmount,None,None,None)
> CallCurrency         = property(GetCallCurrency, None, None, None)
>
> more....properies..etc.
>
> For debugging purposes, I would like to traverse the class listing out
> all the properties.


for attr in dir( yourclass ):
    if repr( yourclass.__dict__[ attr ] ).startswith( '<property' ):
        print 'This looks like a property although can be something
else too: ' + attr

:)



More information about the Python-list mailing list