How to use ParseTuple with unknown number of args?

O

ondekoza

Hi,

I am embedding python in a large application, written in C. To allow
access to
the internals of the app, I embedded python as recommended by the
`extending and embedding'-document on python.org. Most functions that
are now callable from python have fixed number of args and are easy
to parse with ParseTuple.

Now I want to be able to add a function to add array data and I cannot
figure out
how this is done.

The resulting python script should look like this.

import embedded_module as em
em.mysimplecall(5)
em.anothersimplecall(4.5)
d=[1,2,3,4,5]
em.arraycall(d)
d.append(99)
em.arraycall(d)

The C-program should be able to retrieve the array, regardless of its
length.
I suspect it must be done using "O" or "O!", but I cannot find any
examples.

Yours
Stefan Schroeder (Ondekoza)
 
O

ondekoza

With some more research on comp.lang.python I found that this topic has
been discussed earlier to some extend.

One recommendation was to use numpy. This would introduce an additional
dependency which I try to avoid.

The earlier posts generally highlight some specific feature of calling
with arrays. Can someone point me to a piece of software, where sth.
like this is actually used?

Stefan S. (Ondekoza)
 
D

Daniel Dittmar

ondekoza said:
The earlier posts generally highlight some specific feature of calling
with arrays. Can someone point me to a piece of software, where sth.
like this is actually used?

Python source/Objects/stringobject.c string_join would be an example if
you only allow a list or tuple.

Python/bltinmodule.c min_max demonstrates how to allow either a sequence
or a variable number of arguments.

Modules/itertools.c has probably lots of examples on how to work with
iterators at the C API level.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top