E
Elie B.
Hi,
I'm new to Python. I'm trying to embbed Python in my Windows
application having some success with redirecting the stdin/out to my
windows application using:
In my C++ code I use PyRun_SimpleString to execute this code:
import sys
import mymodule
class LOGwriter :
def write(self, str):
mymodule.printit(str)
sys.stdout = sys.stderr = LOGwriter()
than adding in C++:
static PyMethodDef mymodule_methods[] = {
{"printit", mymodule_printit, METH_VARARGS, "prints"},
{NULL, NULL, 0 ,NULL} /* sentinel */
};
static PyObject *mymodule_printit(PyObject *self, PyObject* args)
{
char *s;
PyArg_ParseTuple(args, "s", &s);
PrintToWindow(s); <-- my function
return NULL;
}
Well it seems to work ok, until a string with quotes arrives (usualy
when an error occurs). When an error occurs it cuts the error string
after the quote, so I always get
File "
and not the full error string, which should be somthing like File
"<string>", line 3... . I've tried all kind of ways around this, yet
with no sucess. Thanks in advance for any help.
Eli
I'm new to Python. I'm trying to embbed Python in my Windows
application having some success with redirecting the stdin/out to my
windows application using:
In my C++ code I use PyRun_SimpleString to execute this code:
import sys
import mymodule
class LOGwriter :
def write(self, str):
mymodule.printit(str)
sys.stdout = sys.stderr = LOGwriter()
than adding in C++:
static PyMethodDef mymodule_methods[] = {
{"printit", mymodule_printit, METH_VARARGS, "prints"},
{NULL, NULL, 0 ,NULL} /* sentinel */
};
static PyObject *mymodule_printit(PyObject *self, PyObject* args)
{
char *s;
PyArg_ParseTuple(args, "s", &s);
PrintToWindow(s); <-- my function
return NULL;
}
Well it seems to work ok, until a string with quotes arrives (usualy
when an error occurs). When an error occurs it cuts the error string
after the quote, so I always get
File "
and not the full error string, which should be somthing like File
"<string>", line 3... . I've tried all kind of ways around this, yet
with no sucess. Thanks in advance for any help.
Eli