Names changed to protect the guilty

John Roth JohnRoth1 at jhrothjr.com
Sat Oct 7 09:05:05 EDT 2006


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...

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