no __len__ attribute in NodeList or the list base?

S

sndive

i extract class object from an instance of NodeList (minicompat.py)
like so
PyObject *pclass = PyObject_GetAttrString( nodelistinsance,
"__class__");
but
PyObject_GetAttrString(pclass, "__len__")
returns NULL.

i naively added
__len__ = _get_length
to NodeList
but that ends up in endless recursion.

to explain that endless loop i have to assume __len__ is defined
in the NodeList base(list that is)
but i don't see __len__ anywhere in listobject.c!!!

this is in cpython 2.4.4

__len__ is required to be present in NodeList per this:
http://www.python.org/dev/doc/maint24/lib/dom-nodelist-objects.html
 
H

Hrvoje Niksic

i extract class object from an instance of NodeList (minicompat.py)
like so
PyObject *pclass = PyObject_GetAttrString( nodelistinsance,
"__class__");
but
PyObject_GetAttrString(pclass, "__len__")
returns NULL.

Are you sure about that?
import xml.dom.minicompat
xml.dom.minicompat.NodeList
xml.dom.minicompat.NodeList.__len__
xml.dom.minicompat.NodeList() []
_.__class__
_.__len__
to explain that endless loop i have to assume __len__ is defined
in the NodeList base(list that is)
but i don't see __len__ anywhere in listobject.c!!!

The list object has __len__:
<slot wrapper '__len__' of 'list' objects>

It just gets defined in a different way, through a C structure of
function pointers defining sequence operations. (See where
list_length is defined and used.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top