[Pythonmac-SIG] Passing tuples to C

Chris Barker Chris.Barker at noaa.gov
Fri Mar 5 12:10:33 EST 2004


Greg Hoover wrote:
> I'm trying to pass multiple values to a C function. As far as I know, 
> this is done using tuples. Is there anything special required on the 
> python side to pass this tuple?

nope, python ALWAYS uses a tuple to pass arguments to a function. For 
example:

Afunc(a,b,c)

is passing the tuple: (a,b,c) to Afunc. If the function is written in 
Python, the tule is unpacked automagically. If your function ius is C, 
you need to unpack it yourself.



> This is the C function being called. It is in a module called serial. So 
> I've tried calling serial.serial_write((1, "q"))


>serial.serial_write(1, "q")

This one ought to work.

> // Python provides storage for string
> if(!PyArg_ParseTuple(args, "is", &numCharsToSend, &writeBuffer))

you are asking for two arguments, and integer and a string

What happens when you try the above?

-Chris





-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Pythonmac-SIG mailing list