Executing a specific function.

Michael Saunders michael at amtec.com
Fri Mar 29 12:11:39 EST 2002


Martin,

I had seen this API but it requires a "callable". Isn't a callable a PyObject
pointer to a callable function? How do I build the "callable". All I have is a
Python file, "myfile.py" and the name of a function to call "myPthonFunction".

Michael


PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...) 
     Return value: New reference. 
     Call a callable Python object callable, with a variable number of C
     arguments. The C arguments are described using a Py_BuildValue() style
     format string. The format may be NULL, indicating that no arguments are
     provided. Returns the result of the call on success, or NULL on failure.
     This is the equivalent of the Python expression "apply(callable, args)"
     or "callable(*args)". 

"Martin v. Loewis" wrote:
> 
> Michael Saunders <michael at amtec.com> writes:
> 
> > I see that the Python C API provides several interfaces for
> > compiling and executing Python code. But I don't want to just
> > execute some Python code I want to call a particular function within
> > a Python file. How do I call a Python function (from C) in a some
> > .py file?
> 
> It depends on whether you already have a argument tuple, or whether
> you have the arguments as C data. In the former case, use
> PyObject_Call; in the latter case, use PyObject_CallFunction. Also
> notice PyObject_CallMethod.
> 
> HTH,
> Martin
> 
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list