Help with tuples please?
Fredrik Lundh
fredrik at pythonware.com
Tue Dec 7 08:11:31 EST 1999
Arinte <shouldbe at message.com> wrote:
> Here is were my PyArg_ParseTuple is failing...
>
> in python's source getargs.c
>
> if (!PyTuple_Check(args))
>
> PyErr_SetString(PyExc_SystemError,
> "new style getargs format but argument is not a tuple");
>
> I don't understand why that is happening? Is there another way to get the
> value from a PyObject
>
> This is my c++ code...
>
> char* vstr;
> nobj = PyObject_GetAttrString(tobj,"argname"); <-successful, nobj not null
> if(!PyArg_ParseTuple(nobj, "s", &vstr)){ <-here is where it fails
> appcallback()->messageBox("not again");
> }
>
> tobj is an object of the type below from an array (list) that I pass from
> python to c++.
>
> class PossArg:
> argname=""
argname sure looks like a string to me.
the parsetuple function is used to pull tuples apart, mostly
when dealing with argument tuples. but a string is not a
tuple.
to deal with string objects, use the PyString functions:
http://www.python.org/doc/current/api/stringObjects.html
typical usage patterns:
char *p;
int n;
if (PyString_Check(nobj)) {
p = PyString_AS_STRING(nobj);
n = PyString_GET_SIZE(nobj);
... /* use as byte buffer */
}
or:
if ((p = PyString_AsString(nobj)) != NULL)
... /* use as null terminated C string */
</F>
More information about the Python-list
mailing list