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

Andrew Koenig ark at research.att.com
Sat Feb 8 17:09:39 EST 2003


Samuele> I sympathize but the question is really what you prefer your
Samuele> target group to encounter:

Samuele> 1) sys.exit(errs and 1 or 0)
Samuele>     style = bold and "bold" or "italic"

Samuele> or

Samuele> 2) sys.exit(1 if errs else 0)
Samuele>     style = "bold" if  bold else "italic"

Samuele> because (1) idioms are used in practice.

If (1) and (2) were equivalent, I wouldn't care.  But the trouble comes
in stuff like this:

                sys.exit(ok and 0 or errcode)

which, at first glance, appears analogous to (1), but really means

                sys.exit(errcode)

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list