Reputation: 1
Using the C API for Python, how can I create a list and allocate some memory for it? For example, I tried this code to make a list that will store 4 elements, but I get an error saying that it can't assign to operator:
char *buf1 = int* PyMem_New(int, 4)
Upvotes: -1
Views: 2030
Reputation: 729
I believe buf1 needs to be a pointer.
char *buf1 = PyMem_New(int, 4);
Upvotes: -1
Reputation: 799230
PyList_New()
allows you to specify an initial size in the single mandatory argument. Don't forget to actually set the items with PyList_SetItem()
before using the list in Python code though.
Upvotes: 1