Python complaints

Fred L. Drake, Jr. fdrake at
Wed Nov 24 09:50:26 EST 1999

Gordon McMillan writes:
 > >>> def p(score):
 > ...  print "You scored %d point%s" % (score, score==1 and ' ' 
 > or 's')

  The catch is that this only works when the result value for the true 
case is also true.  I often find I want this sort of construct when
the true result is either false or may be either.  The hack to get
around this:

       x = (some.test and [v1] or [v2])[0]

is really nasty in practice, so I find it's typically *far* more
reliable to expand it out to a full-fledged if:

       if some.test:
           x = v1
           x = v2

  Much longer, but more reliable given the lack of ?: (which I'd also
like to see added, though I'm not sure what the syntax should be).


Fred L. Drake, Jr.	     <fdrake at>
Corporation for National Research Initiatives

More information about the Python-list mailing list