Re: python to c API, passing a tuple array
Thanks for the solution!
Farshid Lashkari wrote:
> [EMAIL PROTECTED] wrote:
> > Hi,
> > I want to pass something like this to a C function via the Python C
> > API.
> > mytuple = (("string_one", 1.2, 1.3), ("string_two", 1.4, 1.5), ..,
> > ., )
> > This tuple is dynamic in size, it needs to be 3 X N dimensions. each
> > tuple in the
> > tuple array is of the form (string, float, float) as described above
> >
> > so from python:
> >
> > mytuple = (("string_one", 1.2, 1.3), ("string_two", 1.4, 1.5))
> > api.myCFunction(mytuple)
> >
> > The C api:
> > static PyObject *myCFunction(PyObject *self, PyObject *args)
> > {
> >
> > if (!PyArg_ParseTuple(args, "O", . ?) {
> > printf(" error in PyArg_ParseTuple!\n");
> > return Py_None;
> > }
> >
> > Thanks.
> >
>
>
> Just loop through each item in the arguments and parse the sub-tuple.
> Here is some sample code that doesn't do any error checking:
>
> static PyObject *myCFunction(PyObject *self, PyObject *args)
> {
> int numItems, i;
> PyObject *tuple;
>
> numItems = PyTuple_Size(args);
>
> for(i = 0; i < numItems; ++i)
> {
> tuple = PyTuple_GetItem(args,i);
> if(!PyArg_ParseTuple(tuple,"sff",...) {
> //handle error
> Py_RETURN_NONE;
> }
> }
> }
>
> Also, you need to INCREF Py_None before you return it. Or you can use
> the macro used in the sample code above.
>
> -Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Freeze without a binary
I want to use freeze to create the .o's to then include in a library that will be distributed. When I use freeze it creates a binary and a main, and the main calls some frozenmain func. Obviously I dont want a main() in this code. Do I need to extract the code that was generated by freeze in main like Py_FrozenMain() and call this from somewhere else? This was created in the main() function: extern int Py_FrozenMain(int, char **); PyImport_FrozenModules = _PyImport_FrozenModules; return Py_FrozenMain(argc, argv); In my code i have C funcs that call py file functions which call C funcs. I dont want to ship the py files, but include it in a library with the other .o's Thanks. -- http://mail.python.org/mailman/listinfo/python-list
linking with math.so
hi, My application that contains the .o's that were generated from using "freeze" needs to import math. The point of using freeze was to make a static application that can be shipped as a single entity (it contains the dot o's from libpython2.4.a), vs having to worry about external python dependencies. "importing math" as far as I can tell right now, invokes a shared library (math.so). Now I have a shared library dependency that I dont want. Is there a way to get the math functionality from a dot a or a dot o, so I dont have to make my app dependent on a shared library? cos, sin, and pi which is what I need do not live in the libpython2.4.a - I did an nm on it I'm on linux. thanks, Nancy -- http://mail.python.org/mailman/listinfo/python-list
python to c API, passing a tuple array
Hi,
I want to pass something like this to a C function via the Python C
API.
mytuple = (("string_one", 1.2, 1.3), ("string_two", 1.4, 1.5), ..,
., )
This tuple is dynamic in size, it needs to be 3 X N dimensions. each
tuple in the
tuple array is of the form (string, float, float) as described above
so from python:
mytuple = (("string_one", 1.2, 1.3), ("string_two", 1.4, 1.5))
api.myCFunction(mytuple)
The C api:
static PyObject *myCFunction(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, "O", . ?) {
printf(" error in PyArg_ParseTuple!\n");
return Py_None;
}
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
