"if x == None" raises "'NoneType' object is not callable"

Luc Saffre luc.saffre at gmx.net
Mon Sep 16 15:01:57 CEST 2002


"""
If I define __getattr__() and __setattr__() for a class, then I cannot
test instances of this class for equality with None.

the code example below raises
TypeError: 'NoneType' object is not callable

Strange! Nobody told you to call 'None'! Who knows an explanation?

Python 2.2.1 (#1, Jun 25 2002, 10:55:46)
[GCC 2.95.3-5 (cygwin special)] on cygwin
        
"""

class Row:

   def __init__(self):
      self.__dict__["_values"] = {}

   def __getattr__(self,name):
      try:
         return self._values[name]
      except KeyError,e:
         AttributeError,str(e)
   
   def __setattr__(self,name,value):
      self.__dict__["_values"][name] = value


row = Row()
if row == None: # here it happens.
   print "row instance is None!"



More information about the Python-list mailing list