PyArg_ParseKeywords?

S

Steven Bethard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,212
Messages
2,571,101
Members
47,695
Latest member
KayleneBee

Latest Threads

Top