Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
MRAB ha scritto: I think you're right. I have rewritten my code, a piece at a time, and (and this is very annoying) now it works fine. I really can't understand what went wrong with my old code. Luca. -- http://mail.python.org/mailman/listinfo/python-list

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread MRAB
Mr.M wrote: MRAB ha scritto: Did you specify that the method accepts keywords arguments with METH_KEYWORDS? The function would take parameters for the instance (self), the positional arguments (args) and the keyword arguments (kwargs). http://docs.python.org/c-api/structures.html If you don't

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
MRAB ha scritto: Did you specify that the method accepts keywords arguments with METH_KEYWORDS? The function would take parameters for the instance (self), the positional arguments (args) and the keyword arguments (kwargs). http://docs.python.org/c-api/structures.html If you don't use METH_KEY

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread MRAB
Mr.M wrote: Carl Banks ha scritto: (some declarations omitted here) You probably shouldn't have, that could be where the error is I'd include the whole function up to the call that raises the exception. Thank you so much Carl for your help, i'll provide more info so that you can try to

Re: PyArg_ParseTupleAndKeywords

2010-01-23 Thread Mr.M
Carl Banks ha scritto: (some declarations omitted here) You probably shouldn't have, that could be where the error is I'd include the whole function up to the call that raises the exception. Thank you so much Carl for your help, i'll provide more info so that you can try to fix my errors

Re: PyArg_ParseTupleAndKeywords

2010-01-22 Thread Carl Banks
On Jan 22, 3:23 pm, "Mr.M" wrote: > Hi, > > i can't understand what i'm doing wrong. I have a c/api that implements > a new class. > In (initproc) function i have somethink like this: > > [code] > > (some declarations omitted here) You probably shouldn't have, that could be where the error is

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

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