[Python-Dev] [Python-3000] How to specify keyword-only arguments from C?

Alexandre Vassalotti alexandre at peadrop.com
Fri Jun 6 05:43:59 CEST 2008


On Thu, Jun 5, 2008 at 11:18 PM, Alexandre Vassalotti
<alexandre at peadrop.com> wrote:
> On Thu, Jun 5, 2008 at 10:14 PM, Mark Hammond <mhammond at skippinet.com.au> wrote:
>> Set an error if the 'arg' tuple doesn't have a length of zero?
>>>> Oh, that isn't a bad idea at all. I will try this. Thanks!
>
Worked flawlessly!
Just for the archives, here's how it looks like:
static int
Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
{
 static char *kwlist[] = {"file", "encoding", "errors", 0};
 PyObject *file;
 char *encoding = NULL;
 char *errors = NULL;
 if (Py_SIZE(args) != 1) {
 PyErr_Format(PyExc_TypeError,
 "%s takes exactly one 1 positional argument (%zd given)",
 Py_TYPE(self)->tp_name, Py_SIZE(args));
 return -1;
 }
 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss:Unpickler", kwlist,
 &file, &encoding, &errors))
 return -1;
...
Thank you, Mark, for the tip!
-- Alexandre


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /