Re: [capi-sig] expression as argument of a object
nirmoy das <nirmoy.aiemd@gmail.com> writes:
ex:column_family('keyspace', 'CF', comparator_type=comparator)
You cannot use PyObject_CallObject to pass keyword arguments to a function; use PyObject_Call. The easiest way is to use Py_BuildValue to create the positional and the keyword arguments. For example:
/* error checking omitted for brevity */
PyObject *args, *kwds, *ret;
args = Py_BuildValue("ss", "keyspace", "CF");
kwds = Py_BuildValue("sO", "comparator_type", comparator");
ret = PyObject_Call(column_family, args, kwds)
Py_DECREF(args);
Py_DECREF(kwds);
On 22.11.2012 08:43, Hrvoje Niksic wrote:
nirmoy das <nirmoy.aiemd@gmail.com> writes:
ex:column_family('keyspace', 'CF', comparator_type=comparator)
You cannot use PyObject_CallObject to pass keyword arguments to a function; use PyObject_Call. The easiest way is to use Py_BuildValue to create the positional and the keyword arguments. For example:
/* error checking omitted for brevity */ PyObject *args, *kwds, *ret; args = Py_BuildValue("ss", "keyspace", "CF"); kwds = Py_BuildValue("sO", "comparator_type", comparator");
Small typo:
kwds = Py_BuildValue("{sO}", "comparator_type", comparator);
The braces tell Py_BuildValue to create a dict.
For better readability, it also good to add the parens to the args format string:
args = Py_BuildValue("(ss)", "keyspace", "CF");
See http://docs.python.org/3/c-api/arg.html#Py_BuildValue
for more information.
ret = PyObject_Call(column_family, args, kwds) Py_DECREF(args); Py_DECREF(kwds);
You should probably also have a look at this tutorial:
http://docs.python.org/3/extending/extending.html#calling-python-functions-f...
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, Nov 22 2012)
Python Projects, Consulting and Support ... http://www.egenix.com/ mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/
"M.-A. Lemburg" <mal@egenix.com> writes:
kwds = Py_BuildValue("sO", "comparator_type", comparator");
Small typo:
kwds = Py_BuildValue("{sO}", "comparator_type", comparator);
The braces tell Py_BuildValue to create a dict.
Yup, sorry about that.
For better readability, it also good to add the parens to the args format string:
args = Py_BuildValue("(ss)", "keyspace", "CF");
I concur. Likewise, dict can be expressed as "{s:O}", which reminds of the dict building syntax in Python.
participants (2)
-
Hrvoje Niksic
-
M.-A. Lemburg