iterator support (in ext. module)

Helmut Jarausch jarausch at igpm.rwth-aachen.de
Mon Jun 28 11:00:32 CEST 2004


Hi,

sorry for the questions but I'm not sure I understand the
C_API docu.

In an own extension module I have a new type called Hitlist,
which has the methods  'first', 'last', 'next' and 'previous'.
Now I'd like to support iterating on this type, e.g. like

HL= Hitlist(...)
for Rcd in HL:

and also

for Rcd in HL.reverse() :

What do I need to implement to get that functionality?
Unfortunately the chapter 10.8 'Supporting the Iterator Protocol' of the
(devel) docu seems to be empty.

What should PyTypeObject.tp_iter be set to? Can I just return 'self'
and is PyTypeObject.tp_iternext an alias for my 'next' method?

Does a call to 'PyTypeObject.tp_iter' reset the iterator s.t. 
'tp_iternext' returns the first object when called afterwards?

Many thanks for your help,
Helmut.

(P.S. I'm using Version 2.4 -cvs)

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Python-list mailing list