By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

no __len__ attribute in NodeList or the list base?

P: n/a
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/maint2...t-objects.html
Nov 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sn****@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.)
Nov 15 '07 #2

P: n/a
On Nov 15, 3:09 am, Hrvoje Niksic <hnik...@xemacs.orgwrote:
snd...@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?
my apologies for the false alarm.
i was calling __len__ on Element rather than NodeList
thank you
Nov 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.