calling Python from C: I can't get this part.

Michael P. Reilly arcege at shore.net
Wed Dec 15 11:19:34 EST 1999


Very Frustrated <rwadkins at flash.net> wrote:
: Okay, almost there.  This is adapted from callback2 in the SWIG examples.

[snip]

: Now, here's the Python version of the C evaluation function.  It takes a
: Chrom_Ptr argument (again, a string) and operates on it.  It works fine
: as long as it's called from within Python.  The problem is that when it's
: used as a callback, it doesn't work.  I believe this is due to alteration
: to the Chrom_Ptr chrom argument when the function is called with :

:    arglist = Py_BuildValue("s", chrom); /* the chrom pointer as string?*/
:    result =  PyEval_CallObject(func, arglist);

I would say off hand that you need to get your arguments right.  Functions
are passed a tuple of values, not the value itself.  Try either:
  arglist = Py_BuildValue("(s)", chrom);
  result = PyObject_CallObject(func, arglist);
or:
  result = PyObject_CallFunction(func, "s", chrom);

The documented API is PyObject_Call*, not PyEval_*; it would probably
be better to use those routines instead.

  -Arcege




More information about the Python-list mailing list