For review: PEP 308 - If-then-else expression
Ian Bicking
ianb at colorstudy.com
Fri Feb 7 16:16:25 EST 2003
On Fri, 2003-02-07 at 13:47, holger krekel wrote:
> result = obj() if callable(obj)
>
> should indeed set the result to None if the condition evalutes
> to false. I don't think there is any other sensible result
> other than 'None'. But of course,
>
> result = obj() if callable(obj) else None
>
> would be more explicit. The question is whether my suggestion
> has enough use cases and is thus practical enough.
To me (obj() if callable(obj)) makes sense without the else. It's like
a function that implicitly returns None, or the .get() method on
dictionaries (without the second argument). Though admittedly I did not
recognize this behavior when I first learned Python, and it was only
later that I started depending on None being returned implicitly.
--
Ian Bicking ianb at colorstudy.com http://colorstudy.com
4869 N. Talman Ave., Chicago, IL 60625 / 773-275-7241
"There is no flag large enough to cover the shame of
killing innocent people" -- Howard Zinn
More information about the Python-list
mailing list