On 31-May-10 17:15 PM, Lie Ryan wrote:
On 05/31/10 05:10, Colin J. Williams wrote:
On 30-May-10 01:50 AM, Nathan Rice wrote:
             On 27-May-10 08:48 AM, Xavier Ho wrote:
              >   On 27 May 2010 22:22, HH<henri...@gmail.com
             <mailto:henri...@gmail.com>>  <mailto:henri...@gmail.com
             <mailto:henri...@gmail.com>>>   wrote:

              >
              >            if (width == 0 and
              >                height == 0 and
              >                color == 'red' and
              >                emphasis == 'strong' or
              >                highlight>   100):
              >                raise ValueError("sorry, you lose")
              >
              >
              >   I've gotta say - I've bumped into this problem before,
             and I'm sure many
              >   other have - this is a valid question. It just hasn't
             bothered me enough
              >   to ask...
              >
              >   Correct me if I'm wrong, but I think the following is
             equivalent, and
              >   looks better. Although this won't fix all ugly cases in
             that problem..
              >
              >   if (width, height, color, emphasis) == (0, 0, 'red',
             'strong') or
              >   highlight>   100:
              >         raise ValueError("sorry, you lose")
              >
              >   Cheers,
              >   Xav

             but nobody commented.

             Colin W.


         Colin:
         Sure, you can do it that way.  IMO, though, the OP was  wrong,
         and so
         is the PEP.  Source code is meant to communicate.  So it must
         transmit
         the correct information to the computer; it also must inform your
         coworkers.  That means that you have a responsibility to care
what
         they think, though you privately have your opinions.  Another
reason
         the PEP is faulty in this circumstance is that a misplaced
         backslash,
         or a missing one, is easily found and fixed.  A misplaced
         parentheses,
         or just one of a pair, will transform your source code into
         something
         which may compile and then give faulty results:  a disaster.
         So keep it simple, and make it legible.
         Yours,
         John


     IMHO complete garbage, if your editor doesn't show misplaced or
     missing parenthesis by highlighting you're using the wrong editor :)



Perhaps the arrangement below shows the matching a little better than
the Xav suggestion.  The main point is that, to me, the tuple shows the
item by item matching better than a series of and clauses:

# tif.py

(width, height, color, emphasis)= 0, 0, 'red', 'strong'
highlight= 99
if (width, height, color, emphasis) ==      \
    (    0,     0,  'red', 'strong') or highlight>   100:
        raise ValueError("sorry, you lose")

How about:

all(a == b for a,b in ((width, 0), (height, 0), (color, 'red'),
(emphasis, 'strong'))))

You need to add "or highlight > 100"



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to