PyObject_CallFunction with keywords?

Thomas Heller theller at python.net
Wed Apr 2 04:23:57 EST 2003


woodsplitter at rocketmail.com (David Rushby) writes:

> Richard Cook <rcook at llnl.gov> wrote in message news:<mailman.1049251384.31007.python-list at python.org>...
> > 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.

Even when programming for Python 2.2, you should at least sometimes peak
in the devel version of the docs:

http://starship.python.net/crew/theller/pyhelp.cgi?keyword=PyObject_Call&version=devel

Thomas




More information about the Python-list mailing list