Using isA and getA in a python way
Andrew Dalke
adalke at mindspring.com
Mon Sep 20 12:52:03 EDT 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)()
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list