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
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
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
_text = "text for free_text")
ok, every time the code fails i get this exception:
TypeError: expected string or Unicode object, tuple found
so, i think for some reason PyArg_ParseTupleAndKeywords receives "args"
as a touple instead of something else.
This is ever
ot;text for free_text")
ok, every time the code fails i get this exception:
TypeError: expected string or Unicode object, tuple found
so, i think for some reason PyArg_ParseTupleAndKeywords receives "args"
as a touple instead of something else.
This is ever
"end_time",
> "storage_time",
> "flags",
> "bytes_sent",
> "bytes_received",
&g
"end_time",
"storage_time",
"flags",
"bytes_sent",
"bytes_received",
"b", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
&b))
return NULL;
return Py_BuildValue("(CC)", a, b);
}
It's not related to default values. foo(x=30) should raise an error; the
allowed parameter names are only
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
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_ParseTupleAndKeywor
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
>>
>> 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
, 2009 at 3:02 PM, Case Vanhorsen wrote:
> 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 underst
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?
> Rega
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:
>
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", kwlis
e it may have had. In other words, the optional character
> arguments
> that are skipped seem to be nulled by PyArg_ParseTupleAndKeywords().
The following code seems to work fine for me:
static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
{
int a=6
kipped seem to be nulled by PyArg_ParseTupleAndKeywords().
--
http://mail.python.org/mailman/listinfo/python-list
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))
&g
wlist[] = {"a", "b", NULL};
> if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> &b))
> return NULL;
> ...
>
> then the following works:
>
> >>> foo('a')
> >>> foo('a','b
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(
"foochar", NULL};
> if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist,
> &foochar))
> return NULL;
> ...
>
> The question remains the same: why can't I pass a single character
> argument to this function under Python3.1?
>
> Thanks
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, &
gs, PyObject *kwrds)
{
char foo;
char *kwlist[] = {"foo", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwrds, "c", kwlist, &foo))
return NULL;
...
In Python3.0 this also works, but in Python3.1 I get the following
error:
TypeError: argument 1 must be a byte st
Steven Bethard wrote:
Thanks for the pointers. What's the "doco gadget" you're talking about?
I conclude from this question that you are not using a Windows python.
I suspect, therefore, the answer is Gilda Ratner's " Never mind."
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.o
John Machin wrote:
Well I just fired up the doco gadget and pasted
"PyArg_ParseTupleAndKeywords" into the Search box and the 2nd
reference it came up with was this:
manual: Python/C API Reference Manual
section: 5.5 Parsing arguments and building values
The 1st, 3rd & 4th r
me to the documentation on how
> PyArg_ParseTupleAndKeywords, etc. work? In particular, I can't figure
> out how the format arg to vgetargskeywords should be specified...
>
Well I just fired up the doco gadget and pasted
"PyArg_ParseTupleAndKeywords" into the Search box and the 2nd
re
Steven Bethard a écrit :
I'm just starting to play around with the Python source. (Specifically,
I'm looking at adding a key argument to max/min like sorted has.) Can
anyone direct me to the documentation on how
PyArg_ParseTupleAndKeywords, etc. work? In particular, I can't
I'm just starting to play around with the Python source. (Specifically,
I'm looking at adding a key argument to max/min like sorted has.) Can
anyone direct me to the documentation on how
PyArg_ParseTupleAndKeywords, etc. work? In particular, I can't figure
out how th
29 matches
Mail list logo