By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,437 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,437 IT Pros & Developers. It's quick & easy.

How to use ParseTuple with unknown number of args?

P: n/a
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)

Jul 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

Jul 18 '06 #2

P: n/a
ondekoza wrote:
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

Jul 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.