embedding Python and changing stdin, stdout and stderr

Vincent Touquet vincent.touquet at gmail.com
Thu Sep 2 12:54:17 EDT 2004


Hi,

In a project where I have embedded Python in a C++ application, I have
the need to replace what Python considers to be stdin, stdout and/or
stderr.

In sysmodule.c in the Python sources, I find the following lines of
code:

sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
...
PyDict_SetItemString(sysdict, "stdin", sysin);

Where stdin is the C constant FILE pointer and sysin is a PyObject
pointer.

Would it be feasible for me to provide my own PyFile to replace sysin
in sysdict ?  It would seem to me that it would be sufficient to
provide the Python interpreter with a different standard in/out/err
than the one provide by the OS (through C).

best regards,

Vincent



More information about the Python-list mailing list