On Mar 20, 2008, at 3:57 AM, Francesco Guerrieri wrote: > Hi, it's always me :-) > I've been looking for a standard way for passing from a c array to a > python object, eg a list. > In the primes example, this is solved by creating both the array > (with a fixed size, but now I know how to handle it :-) ) and the > list, > and then appending the relevant prime numbers to the list. > > Is this the idiomatic approach? > I have looked for something similar in the sage codebase but > didn't find something relevant. > > So if I have an array, do I have always to do something like this? > > for i from 0 <= i < size_of_array: > my_list.append(array[i]) > return my_list
The numpy suggestion is good, but I could also suggest [array[i] for i from 0 <= i < size] which should both be faster and easier to read. - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
