SystemError: new style getargs format but argument is not a tuple
Alex Farber
farber at cpan.org
Wed Mar 1 12:53:35 EST 2000
Dear colleagues,
I am trying to find out, why Py_CompileString() returns NULL -
1) because the string is incomplete, like in "for i in [1,2]:"
2) or because of some other syntax error, like "x=1.1.1"
So here is my code:
/* gcc -I/usr/include/python -lpython1.5 -o eof eof.c */
#include <stdio.h>
#include <Python.h>
#include <compile.h>
int main(int ac,char* av[])
{
char *string;
PyObject *globals, *source, *error, *dummy;
Py_Initialize();
globals = PyDict_New();
PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins());
source = Py_CompileString("for i in i [1,2]:", "<stdin>", Py_file_input);
if (source == NULL) {
if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
if(!PyArg_ParseTuple(PyExc_SyntaxError, "(sO)", &string, &dummy)) {
if (!strcmp(string,"unexpected EOF while parsing"))
printf("More input is needed: %s\n", string);
else
printf("Some syntax error: %s\n", string);
}
}
PyErr_Print();
}
Py_XDECREF(globals);
Py_XDECREF(source);
Py_Finalize();
exit(0);
}
However I get: "argument is not a tuple".
And I am just trying to get the string value,
which is inserted in Python/pythonrun.c:
static void
err_input(err)
perrdetail *err;
{
...
case E_EOF:
msg = "unexpected EOF while parsing";
break;
...
w = Py_BuildValue("(sO)", msg, v);
Py_XDECREF(v);
PyErr_SetObject(PyExc_SyntaxError, w);
Py_XDECREF(w);
}
Does anyone have an advice for me?
Maybe I can check E_EOF somehow?
Thank you!
Alex
More information about the Python-list
mailing list