Question about __getattribute__/__getattr__
Mark McEahern
marklists at mceahern.com
Mon Sep 30 11:52:08 EDT 2002
> if cached_value == None:
This is an aside, but comparison to None should be via identity rather than
equality; e.g.,
if x is None:
or:
if x is not None:
Why? Because you may be comparing an object that barfs when compared to
None via its own __eq__ method. It's a subtle point and I don't think I'm
explaining it very well. Suffice it to say, if you really are comparing to
None, use is/is not. If you want to test whether an object is/is not zero,
then use:
if x:
or:
if not x:
// m
More information about the Python-list
mailing list