473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

PyArg_ParseKeywords?

Is there a PyArg_ParseKeywords along the lines of
PyArg_ParseTupleAndKeywords? I want to parse only the keywords,
ignoring the arguments. Currently I do this with something like:

const char *format = "O:min";
static char *kwlist[] = {"key", 0};
PyObject *empty_args = Py_BuildValue("()");
if (!PyArg_ParseTupleAndKeywords(empty_args, kwds, (char *)format,
kwlist, &keyfunc)) {
return NULL;
}
Py_DECREF(empty_args);

but I'm hoping there's a way around creating an empty argument tuple. I
assume I could just use PyDict_GetItemString on the kwds directly, but
I'd rather not have to duplicate all the error checking in vgetargskeywords.

(If you're wondering why I would want such a thing, the application is
adding a 'key' keyword argument to min/max, and it can't be considered
as a positional parameter or the max(a, b, c, key=func) form will treat
func as another item to be compared.)

Steve
Jul 18 '05 #1
0 982

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.