When to use None
Michael Hudson
mwh21 at cam.ac.uk
Sat Feb 5 08:05:45 EST 2000
More information about the Python-list mailing list
Sat Feb 5 08:05:45 EST 2000
- Previous message (by thread): When to use None
- Next message (by thread): When to use None
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
neelk at brick.cswv.com (Neel Krishnaswami) writes: > 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'. I guess the point is that I can't think of a good reason for an object to masquerade as None. I generally use None to mean exactly that; a void, nothing (like nulls in SQL, I guess). I suppose there are times when None is an allowable value, and then something that's a bit like None is more reasonable (to me, anyway). Cheers, Michael
- Previous message (by thread): When to use None
- Next message (by thread): When to use None
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list