Iterative argument conversion in C extensions

Chris McDonough chrism at digicool.com
Sun Jan 30 23:41:33 EST 2000


Hi,

I'm working on a C extension that must accept arbitrary positional
arguments of Python types string, int, and float and convert those to
their C equivalents (int, char, float).

I'm sort of stuck, however, on creating a C routine which can accept and
deconstruct into C equivalents the elements of the passed-in Python
tuple that may contain arbitrary Python object types of int, float, and
string arbitrarily positioned within the tuple.  It doesn't help that I
don't know much C, either :-)  

To explain a little better, I'd like to be able to call a function
within a C extension with arbitrary arguments like so:

mymodule.function(1,"string",2.0)

or maybe

mymodule.function("string", "another string", 2.0, 1, "wow")

or maybe even

mymodule.function("lonely string")

I imagine the best thing to do here is to construct a wrapper for the
function that determines the number of passed in arguments and their
types.  The wrapper would then shove what it knows about the arguments
into a dictionary of some kind which then would be shoved into the tuple
that is passed to the C extension module.  But deconstructing that
Python dictionary and retrieving and marshalling its contents within C
is sort of beyond me.

Does anyone have an example of doing such a thing?

Many thanks in advance!

-- 
Chris McDonough
Digital Creations, Inc.
Zope - http://www.zope.org



More information about the Python-list mailing list