newbie list processing question

Daniel Ashbrook <[email protected]>
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
So I've done a lot of Google searching and haven't found an answer to 
this question, or at least one that I understand.

I'm trying to write some fairly simple list-processing code using pyrex. 
As a simple example, let's say I wanted to translate this:

def addOne(l):
   assert(isinstance(l, list))
   for i in xrange(l):
     l[i] += 1

or even this:

def addOne(l):
   return [i+1 for i in l]

to fast-running pyrex code. How can I actually access the list properly? 
(I should point out that in my real problem, I actually need random 
access to the list.) I've seen some talk of using PyObject_AsWriteBuffer 
to do it, but the post was related to array objects, which I'd rather 
not use unless I have to. I've been trying to figure it out using 
PyList_GetItem/SetItem and so on, but it seems extremely convoluted, like:

PyList_SetItem(l,i,PyInt_FromLong(PyInt_AsLong(PyList_GetItem(l,i))+1))

Surely there is another way! (Plus that line doesn't work - trying to 
use "for i from" gives me errors about making i an integer from a 
pointer without a cast.)

Any tips? If the person who maintains documentation for pyrex is 
reading, I'd love to see a simple list-processing example included.

Thanks!


dan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.