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

Gordon McMillan gmcm at hypernet.com
Tue Nov 9 04:15:01 CET 1999


sessile writes:

> 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)
> 
> The list was created by 'PyList_New()' and populated
> using 'PyList_SetItem()'.  I get the same error message
> regardless of the data type held in the list.  I can
> access each element of the list just fine, but I don't
> always know how many there are.  Is there a reasonable
> way for me to find the length of these lists in Python
> other than returning the length from the extension as a
> separate object?  

Most likely you've clobbered the name "len" by binding it to an 
integer (as the error msg so tersely implies). Probably nothing 
wrong with your extension.

- Gordon




More information about the Python-list mailing list