Python Lists -> C arrays?

D-Man dsh8290 at rit.edu
Sat Nov 4 21:56:48 CET 2000


If you're writing C code, that should be easy.  The algorithm would be to malloc an array of size "len( mylist )".  Then iterate through the list copying the values to the array.  Or perhaps populating the array with pointers to the PyObjects in the list (and maintaining the correct ref count).

-D


On Fri, 03 Nov 2000 16:29:13 Michael Brown wrote:
 | Hi.
 | 
 | I've been looking at the python extension features and noticed that
 | Python has an easy way to convert integer elements in C
 | into a python list using the Py_BuildValue function.  Is there an easy
 | way to do this in reverse, say to convert Python lists
 | (not tuples) into C arrays (strings, int, float)?
 | 
 | Thanks.
 | 
 | Mike
 | 
 | --
 |         Michael F. Brown
 |         email:  mikeb at srl.css.mot.com
 | 
 | 
 | 
 | <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
 | <html>
 | Hi.
 | <p>I've been looking at the python extension features and noticed that
 | Python has an easy way to convert integer elements in C
 | <br>into a python list using the Py_BuildValue function.&nbsp; Is there
 | an easy way to do this in reverse, say to convert Python lists
 | <br>(not tuples) into C arrays (strings, int, float)?
 | <p>Thanks.
 | <p>Mike
 | <pre>--&nbsp;
 | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Michael F. Brown
 | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; email:&nbsp; mikeb at srl.css.mot.com&nbsp;&nbsp;
 | </pre>
 | &nbsp;</html>
 | 






More information about the Python-list mailing list