Using isA and getA in a python way

Andrew Dalke adalke at
Mon Sep 20 18:52:03 CEST 2004

C Gillespie wrote:
> if obj.isA(): return obj.getA()
> if obj.isB(): return obj.getB()
> Is there a nicer way of doing this, perhap going through the list
> ['A','B','C',..

(Warning: Untested code.  Should be enough to
lead you to the right documentation if it doesn't work)

for name in ['A', 'B', 'C']:
     if getattr(obj, 'is' + name)():
         return getattr(obj, 'get' + name)()

				dalke at

More information about the Python-list mailing list