using lists in C-extensions?

Marcus Stojek stojek at part-gmbh.de
Sat Feb 16 09:48:10 EST 2002


Hi,

Hi,

I'm still fighting with my optimization problem.
After I got a lot of very useful hints from this
group I have accelerated my search problem by a
factor of app. 50. As always this was achieved by
structuring the data efficiently, avoiding expensive
operations in loops and so on. THANKS.

But I am still far too slow. So I have to go for C.
My problem is, that I have to pass a list (or actually
a couple of lists) to the C routine and after performing
the calculations, returning them to Python. As far as
I understand things, I have to use PyArg_Parse() and
Py_BuildValue() for this, right?

Both expect a format string like "s", "i" or something.
I didn't find a format string for a list ;-)
[items] could work, but my lists are huge and I can't
list the members one by one.

There is this strange "O" respectively "O&" which might
be suitable, but I don't know how.

So could anyone give an example or tell me where to look?

------------
EXAMPLE:

list=[]
for i in range(100000):
    list.append(i)

listnew=map((lambda x:x+1),list)  # this should be coded in C

------------
Maybe things are easier with scipy.weave, but one important
point is that I can use py2exe or installer. Is that possible
with weave? (Windows NT)

Does SWIG handle this problem?

Thanks again,
Marcus





More information about the Python-list mailing list