Too much code - slicing

Duncan Booth duncan.booth at invalid.invalid
Tue Sep 21 04:17:00 EDT 2010


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> That's sheer and unadulterated nonsense. The fact is that Guido changed 
> his mind about ternary if after discovering that the work-around
> 
> true-clause and condition or false-clause
> 
> is buggy -- it gives the wrong answer if true-clause happens to be a 
> false value like [], 0 or None. If I recall correctly, the bug bit Guido 
> himself.
> 
> The and-or hack, which was *very* common in Python code for many years 
> and many versions, follows the same pattern as ternary if:
> 
> true-clause if condition else false-clause
> 

I guess you have worked hard to forget the and-or hack. It was actually:

  condition and true-clause or false-clause

so its not quite the same pattern.

Of course there's also the bug fixed version which I suspect was so ugly it 
was the real trigger for getting a real ternary operator:

  (condition and [true-clause] or [false-clause])[0]


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list