Can't use len() on returned PyList object?

Malcolm Tredinnick malcolmt at smart.net.au
Mon Nov 8 22:30:23 EST 1999


On Mon, Nov 08, 1999 at 09:12:17PM -0500, sessile at in-gen.net wrote:
> Why can't I use 'len()' to find the length of a list
> returned from my new extension module?  The error is
> shown as:
> 
>     TypeError: call of non-function (type int)

You have probably used 'len' as an integer variable at some point
previously in the program. This would have overwritten the builtin
declaration of len as a function.

You can test this in the interpreter by seeing what type(len) returns (or
even just print len). Programmatically, see if type(len) == type(1). If it
does then you (or one of your imported modules) have redefined len. :-(

Tracking this sort of thing down can be annoying sometimes, because not
only do you have to look through your own program, but also be suspicious
of any modules where you did "from module_name import *" (although, of
course, you can pretty much eliminate all the standard modules, since they
have withstood the test of time for this conflict).

Cheers,
Malcolm Tredinnick




More information about the Python-list mailing list