no __len__ attribute in NodeList or the list base?
Hrvoje Niksic
hniksic at xemacs.org
Thu Nov 15 04:09:36 EST 2007
sndive at gmail.com writes:
> 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
<class 'xml.dom.minicompat.NodeList'>
>>> xml.dom.minicompat.NodeList.__len__
<slot wrapper '__len__' of 'list' objects>
>>> xml.dom.minicompat.NodeList()
[]
>>> _.__class__
<class 'xml.dom.minicompat.NodeList'>
>>> _.__len__
<slot wrapper '__len__' of 'list' objects>
> 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__:
>>> list.__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.)
More information about the Python-list
mailing list