Python paradigms
Andrew Dalke
dalke at acm.org
Sat Apr 8 21:06:17 EDT 2000
Me:
>>How about
>> x = getattr(a, "weeble", 0) + getattr(b, "wombat", 0)
Nick Maclaren:
>Thank you, yes, that does deal with that specific example. But
>it does not extend to the general case.
Ahh, I thought the general case was "test if something exists
and, if so, get data from it, otherwise use a given value."
What is the general case you are interested in - that of C's
ternary ?: operator? I've rarely missed it, because most of
the subcases are handled by things like getattr.
Andrew
dalke at acm.org
More information about the Python-list
mailing list