473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use ParseTuple with unknown number of args?

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
2 1450
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nikolai Onken | last post by:
Hey List, I was wondering how I can get all Attributes of a XML-Tag without knowing them. The XML could look like following: <plugin> <args level="1" depth="2"/> </plugin> <plugin> <args...
3
by: JIM.H. | last post by:
Hello, I have only one form with a listbox:lbFileContent, and I have this code in Public Class Form1. Public Shared Sub UploadFile(ByVal fileNamePath As String) Dim reader As StreamReader = New...
3
by: Torrent | last post by:
When Trying to Load an XSLT File with the XslTransform i got a rather annoying Exception being thrown "System.Xml.XPath.XPathException: XsltContext is needed for this query because of an unknown...
0
by: David Mediavilla | last post by:
I am trying to check a SOAP signature with WSE 1.0 SP1, but with a certain transform I only get an "Unknown tranform" exception. The SOAP signature is like this: <ds:Signature>...
10
by: ndm | last post by:
Hi, Just wondering if any one knows a way to pass and enumerate an unknown number of parameter to a VB function. I want to create a Min/Max functions that can: a) take an variable number of...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
7
by: Howard | last post by:
Can c# pass a unknown number of parameters like in javascript? the parameters could be different types eg. myMethod(string a, param) { int a = param; string b = param; }
4
by: Anthra Norell | last post by:
Hi, I keep working around a little problem with unpacking in cases in which I don't know how many elements I get. Consider this: def tabulate_lists (*arbitray_number_of_lists): table = zip...
4
by: omono84 | last post by:
I know that this should be rather simple but i seem to be missing a step to get it to work. and have been unable to find a solution on the net. The aim is that I click on the open button to find...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.