473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

no __len__ attribute in NodeList or the list base?

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
2 2167
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
10
by: george young | last post by:
I had developed the habit of using the neat python form: if someinstance: someinstance.memb() because it seems cleaner than "if someinstance is not None". {please no flames about "is not None"...
3
by: MackS | last post by:
I'm new to Python. In general I manage to understand what is happening when things go wrong. However, the small program I am writing now fails with the following message: AttributeError: ClassA...
2
by: Howard Jess | last post by:
Given the html at the end of this message, I see how a DOM NodeList exhibits its "live" behavior; that is, adding elements to a document can change any NodeList variables, when there's *no* code...
1
by: D Ratcliffe | last post by:
Hello In a nutshell, I am looping through an XML document in a for loop, and I want to insert a given value as an element to each tag as I go along. i.e.: for (int i=0; i <...
2
by: K B | last post by:
I bit new to this. My xml files contains the following nodes: <root> <WI Title="Test1"> <Role Name="Legal"/> <Role Name="PM"/> </WI> <WI Title="Test1"> <Role Name="Legal"/> <Role...
6
by: btknorr | last post by:
The following html and javascript combination fails to execute in Internet Explorer...does anyone know why? If you change the input's attribute "name" to anything other than "item" it works just...
10
by: Nikhil | last post by:
which one is better? and why? __len__() is a built-in function of the list object and is updated along with the list object elements and will be useful incase the list is very huge. len() is...
1
by: krunaldsoni | last post by:
Let me give you my problem statement: <positiondata > <touchpad reportedFingers="2" /> <timestamp user="Dev" time="1252088979018" /> <reported2d x="447" y="232" z="31" w="1" finger="0"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.