PyObject_CallFunction with keywords?
Richard Cook
rcook at llnl.gov
Tue Apr 1 21:39:53 EST 2003
Hi,
Short question:
Is it possible to pass keywords to a function with PyObject_CallObject()?
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? The
documentation for PyObject_CallObject says it is equivalent to
apply(o, args), but says nothing about the actual apply syntax:
apply(o, args, keywords)
where keywords is a dictionary.
--
Richard Cook
Lawrence Livermore National Laboratory
Bldg-451 Rm-2043, Mail Stop L-561
7000 East Avenue, Livermore, CA, 94550, USA
phone (925) 423-9605 (work) fax (925) 423-8704
---
Information Management & Graphics Grp., Services & Development Div.,
Integrated Computing & Communications Dept.
(opinions expressed herein are mine and not those of LLNL)
More information about the Python-list
mailing list