question of style

Paul Rubin http
Thu Jul 2 16:02:58 EDT 2009


Simon Forman <sajmikins at gmail.com> writes:
> ## Second snippet
> 
> if self.higher is None:
>     if self.lower is None:
>         return
>     return self.lower
> if self.lower is None:
>     return self.higher
> 
> What do you think?

I'm not sure, but my guess is that what you are really trying to write
is something like this:

   # self.higher and self.lower are each either "available" (i.e.  are
   # not None), or unavailable (are None).  Return the highest of the
   # available values.  If no value is available, return None.

   if self.higher is not None: 
       return self.higher
   elif self.lower is not None: 
       return self.lower
   else: 
       return None



More information about the Python-list mailing list