On 2008-06-04, NickC <[EMAIL PROTECTED]> wrote: > On May 26, 7:32 am, "Joe P. Cool" <[EMAIL PROTECTED]> wrote: >> I saw this "don't need it" pattern in discussions about the ternary >> "if..else" expression and about "except/finally on the same block >> level". >> Now Python has both. > > if/else was added solely because people kept coming up with ways of > embedding a pseudo conditional inside expressions and writing buggy > code in the process. All it really saves you in practice is a bit of > vertical whitespace, so, no, you still don't need it - but if you > insist on doing it, at least there's now an easy way to do it > correctly.
If I remember correctly it was added because one of the python developers was bitten by a bug in the standard library code that was caused by the use of the and-or emulation, mentioned in the FAQ. And although one indeed doesn't need this. There are a lot of things in Python one doesn't need. Python could be limited to single operator expressions. You don't need: x = a * b + c You can write it just like this: x = a * b x = x + c And if you want a list comprehension like the following: ls = [ x * x + 4 for x in xrange(10)] You can of course write it as follows: def sqrplus4(a): rs = a * a return rs + 4 ls = [sqrplus4(x) for x in xrange(10)] Now of course noone would defend such a limitation on the grounds that one doesn't need the general case and that the general case will only save you some vertical space. But when it came to the ternary operator that was exactly the argument used, to defend the lack of it. >> > In Python, the philosophy "we're all consenting adults here" applies. >> >> Please don't sell a missing feature as a philosophy. Say you don't >> need/want >> it. But don't call it philosophy. > > Gosh, and here I thought treating programmers as non-idiots was > actually one of the guiding philosophies in the discussion on python- > dev. I have heard the argument: "Such a feature will be abused too easily" and similar too many times to find this credible. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list