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

Mark McEahern marklists at mceahern.com
Mon Sep 16 09:14:19 EDT 2002


Comparison to None should generally be comparison by identity rather than
equality:

  if x is None:

or:

  if x is not None:

not:

  if x == None:

nor:

  if x != None:

What you might consider is adding a __len__ magic method to your Row class
like so:

  def __len__(self):
    return len(self.values)

Then you can do this:

  r = Row()
  if r:
    ...
  else:
    ...

Cheers,

// mark

-





More information about the Python-list mailing list