Duncan Booth wrote:
Simon Forman <sajmik...@gmail.com> wrote:
...
if self.higher is self.lower is None: return
...

As a matter of style however I wouldn't use the shorthand to run two 'is' comparisons together, I'd write that out in full if it was actually needed here.

Speaking only to the style issue, when I've wanted to do something like
that, I find:

      if self.higher is None is self.lower:
          ...

more readable, by making clear they are both being compared to a
constant, rather than compared to each other.

More often, I've used code like:

      if <expr1> is not None is not <expr2>:
          ...

since I am usually working on non-defaulting cases in the body.
I find the form above simpler to read than:

      if <expr1> is not None and <expr2> is not None:
          ...

I do draw the line at two, though, and with three or more I'll
paren-up a list of parallel comparisons:

      if (<expr1> is not None
        and <expr2> is not None
        and <expr3> is not None):
          ...

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to