PyObject_CallFunction with keywords?

David Rushby woodsplitter at
Wed Apr 2 09:30:59 CEST 2003

Richard Cook <rcook at> wrote in message news:<mailman.1049251384.31007.python-list at>...
> Long question:
> I am using an embedded Python interpreter in our C program to execute 
> a method from a Python module (pexpect, to be exact).  At a certain 
> point, I wish to do the equivalent of the following Python code in my 
> C code:
> result =  obj.expect("hello", timeout=50);
> So I have a PyObject *f which points to obj.expect, and a PyObject *s 
> which is a list containing the string "hello".  I figure I have to do:
> PyObject_CallObject(f, s, k)
> where k is the timeout parameter, but this does not match the param 
> list for PyObject_CallObject().
> My question is, how can I pass keyword parameters such as the timeout 
> parameter in my example to a function which accepts them?

With Python 2.2 and later, there's PyObject_Call(callable, args,
kwargs), but strangely, it seems to have been omitted from section
"6.1 - Object Protocol" of the standard docs.

PyObject *PyObject_Call(PyObject *callable_object, PyObject *args,
PyObject *kw);

More information about the Python-list mailing list