Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-21 Thread Gabriel Genellina
En Sat, 19 Dec 2009 07:36:59 -0300, Emeka escribió: Okay if that is the case, why do we need it? By having int a = 65, b = 66 , why should we also have *kwlist[]? static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { int a=65, b=66; char *kwlist[] = {"a", "b", NULL}

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-19 Thread Joachim Dahl
My mistake seems to be that I declared char a, b; instead of int a, b; Thank you for sorting this out. Joachim -- http://mail.python.org/mailman/listinfo/python-list

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-19 Thread Emeka
Okay if that is the case, why do we need it? By having int a = 65, b = 66 , why should we also have *kwlist[]? static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { int a=65, b=66; char *kwlist[] = {"a", "b", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC",

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread casevh
On Dec 18, 10:28 am, Joachim Dahl wrote: > My mistake seems to be that I declared > > char a, b; > > instead of > > int a, b; > > Thank you for sorting this out. > > Joachim I think you need to initialize them, too. -- http://mail.python.org/mailman/listinfo/python-list

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread Case Vanhorsen
On Fri, Dec 18, 2009 at 7:57 AM, Emeka wrote: > Case, > Thanks so much! However, I am still confused. This is what I understood; > foo (a = "a", b = "b") so function , foo,  has default values which are "a" > and "b". pointer kwlist[] is a way of specifying default values . > Regards, > Emeka kwli

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread Emeka
Case, Thanks so much! However, I am still confused. This is what I understood; foo (a = "a", b = "b") so function , foo, has default values which are "a" and "b". pointer kwlist[] is a way of specifying default values . Regards, Emeka On Fri, Dec 18, 2009 at 3:02 PM, Case Vanhorsen wrote: >

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread Case Vanhorsen
On Fri, Dec 18, 2009 at 2:26 AM, Emeka wrote: >    char *kwlist[] = {"a", "b", NULL}; >    if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, > &b)) > I am yet to understand what pointer kwlist[] does and why it is needed? > Regards, > Emeka foo is designed to accept two arguments t

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread Emeka
char *kwlist[] = {"a", "b", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, &b)) I am yet to understand what pointer kwlist[] does and why it is needed? Regards, Emeka On Fri, Dec 18, 2009 at 8:17 AM, casevh wrote: > On Dec 17, 11:14 am, Joachim Dahl wrote: > > In

Fwd: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread Emeka
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { int a=65, b=66; char *kwlist[] = {"a", "b", NULL}; I am yet to understand what kwlist pointer does and why it is needed? if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, &b)) return NULL; re

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread casevh
On Dec 17, 11:14 am, Joachim Dahl wrote: > In the Ubuntu 9.10 version of Python 3.1 (using your patch), there's a > related bug: > > >>> foo(b='b') > > will set the value of a in the extension module to zero, thus clearing > whatever > default value it may have had.  In other words, the optional c

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-17 Thread Joachim Dahl
In the Ubuntu 9.10 version of Python 3.1 (using your patch), there's a related bug: >>> foo(b='b') will set the value of a in the extension module to zero, thus clearing whatever default value it may have had. In other words, the optional character arguments that are skipped seem to be nulled by

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-01 Thread Joachim Dahl
thanks - the patch fixed my problem. Joachim On Dec 1, 5:51 am, casevh wrote: > On Nov 30, 2:18 pm, Joachim Dahl wrote: > > > > > > > I think that "C" encoding is what I need, however I run into an odd > > problem. > > If I use the following C code > > > static PyObject* foo(PyObject *self, PyO

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-11-30 Thread casevh
On Nov 30, 2:18 pm, Joachim Dahl wrote: > I think that "C" encoding is what I need, however I run into an odd > problem. > If I use the following C code > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { >   char a, b; >   char *kwlist[] = {"a", "b", NULL}; >   if (!PyAr

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-11-30 Thread Joachim Dahl
I think that "C" encoding is what I need, however I run into an odd problem. If I use the following C code static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char a, b; char *kwlist[] = {"a", "b", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a, &b

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-11-30 Thread casevh
On Nov 30, 1:04 pm, Joachim Dahl wrote: > Obviously the name of the C function and the char variable cannot both > be foo, > so the C code should be: > > static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) > { >   char foochar; >   char *kwlist[] = {"foochar", NULL}; >   if (!PyA

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-11-30 Thread Joachim Dahl
Obviously the name of the C function and the char variable cannot both be foo, so the C code should be: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { char foochar; char *kwlist[] = {"foochar", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foocha

PyArg_ParseTupleAndKeywords in Python3.1

2009-11-30 Thread Joachim Dahl
I am updating an extension module from Python2.6 to Python3. I used to pass character codes to the extension module, for example, I would write: >>> foo('X') with the corresponding C extension routine defined as follows: static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds) { ch