For review: PEP 308 - If-then-else expression

Aahz aahz at pythoncraft.com
Fri Feb 7 23:43:59 EST 2003


In article <b21rh0$oc9$1 at slb9.atl.mindspring.net>,
Andrew Dalke <adalke at mindspring.com> wrote:
>
>I elsewhere (but towards the end of a longish post) pointed out
>that I will frequently write
>
>x = None
>if s.find("spam") > -1:
>    x = "spammity spam!"
>
>The quick rewrite of this to the ...if..else.. expression is
>
>x = None if s.find("spam") > -1 "spammity spam!"
>
>which is wrong and gets things exactly backwards.
>
>I believe a few people will get it wrong because of this,
>either translating to or from a if/else statement.

You've put your finger on the reason I feel a stronger negative reaction
to this than the listcomps.  It seems rare to me that someone tries to
directly transpose a for loop into a listcomp or vice-versa, but I think
that'll be much more common with this.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Register for PyCon now!  http://www.python.org/pycon/reg.html




More information about the Python-list mailing list