When to use None

Neel Krishnaswami neelk at brick.cswv.com
Fri Feb 4 18:37:40 EST 2000


Michael Hudson <mwh21 at cam.ac.uk> wrote:
> Bernhard Herzog <herzog at online.de> writes:
> >
> > >>> class C:
> > ..     def __cmp__(self, other):
> > ..             return cmp(None, other) 
> > .. 
> > >>> c = C()
> > >>> c == None
> > 1
> > >>> c is None
> > 0
> 
> Yikes! That's impressively devious.
> 
> I-always-*knew*-there-was-a-reason-I-always-use-"is"-ly y'rs

Is it devious?

I always assumed that a __cmp__ method that returned true for a
comparsion with None would have a good reason for doing so, and as a
result I've always tested that with 'obj == None'.


Neel



More information about the Python-list mailing list