[capi-sig] How to manipulate C table as python list ?

Marc marcglec at free.fr
Sun Jan 18 01:06:31 CET 2009


I would like to use a C program which manipulates table
as a python module acting on a list.
My C code is the following:
int sum(int *tab, int n)
  int i, s = 0;
  for (i=0; i<n; i++)
      s += tab[i];

  return s;
Now, I would like to use it as a python module
where tab would be a python list.
I read some examples in the documentation but
the size of the list is always assumed to be known
such that one can use PyArg_ParseTuple
with a format description for each argument.
I would like that my module behave like:
print my_module.sum(a) -> 6
print my_module.sum(b) -> 30

My question is:
which option should I use with PyArg_ParseTuple?
I'm totaly lost with all its option (O, O&, O!, etc)


More information about the capi-sig mailing list