Names changed to protect the guilty

John Machin sjmachin at lexicon.net
Sat Oct 7 15:13:54 CEST 2006


John Roth wrote:
> Aahz wrote:
> > The following line of lightly munged code was found in a publicly
> > available Python library...
> >
> >     if schema.elements.has_key(key) is False:
> >
> > Sorry, just had to vent.
> > --
> > Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/
>
> Uh, guys. IMO, the clearest way of writing this is:
>
> if key not in schema.elements:
>     whatever...
>

Uh, guys, what? You are the 3rd to make that point. Therefore it must
be true.

> Unless, of course, your code has to run in a
> Python release earlier than 2.2. But then you
> wouldn't be testing for the False object anyway.
> 
> 
> 
> John Roth




More information about the Python-list mailing list