"if x == None" raises "'NoneType' object is not callable"
luc.saffre at gmx.net
Mon Sep 16 15:37:21 CEST 2002
Thank you, Mark. Now I will remeber the difference between "is" and "=="!
There is another big bug in my code snippet. If I write::
then the results are also much more as expected :-)
For every undefined attribute I told Python "yes, I have this attribute
defined, and its value is None".
The explanation for this strange message is now clear (at least for my
- Because I used "==" (and not "is"), Python made a deep look into my
object and looked into each attribute, not only the hash()
- One of these attributes was some of those magic functions, perhaps
__cmp__(). And my __getattr__() returned None instead of raising
AttributeError for these attributes which, I admit, if you define them,
should be callable...
Okay... Python is great!
On 9/16/2002 4:14 PM, Mark McEahern wrote:
>Comparison to None should generally be comparison by identity rather than
> if x is None:
> if x is not None:
> if x == None:
> if x != None:
>What you might consider is adding a __len__ magic method to your Row class
> def __len__(self):
> return len(self.values)
>Then you can do this:
> r = Row()
> if r:
More information about the Python-list