why is this failing?

Peter Hansen peter at engcorp.com
Thu Sep 11 17:16:53 EDT 2003


Chris Curvey wrote:
> 
> I've looked at this so long that I must be looking right past it.  This
> code:
> 
> class Page:
>      ##########################################################
>      def write(self, value, row=None, col=None, len=None):
>          print isinstance(value, str)
> 
>          # error occurs on this line
>          print len(value)
> 
> ########################################################
> if __name__ == "__main__":
>      p = Page()
> 
>      p.write("banana")
> 
> is throwing this error:
> 
> True
> Traceback (most recent call last):
>    File "P2.py", line 13, in ?
>      p.write("banana")
>    File "P2.py", line 7, in write
>      print len(value)
> TypeError: 'NoneType' object is not callable

Reading the error more closely, and examining the line that is failing,
you can see that the only call being made is to len(), but the error is
telling you that the name "len" is actually bound to None!  How could
that happen?  Check your list of arguments to the write() method...

Don't use names of builtins and your life will be easier. :-)

-Peter




More information about the Python-list mailing list