embedding python in C++

Syver Enstad syver at NOSPAMcyberwatcher.com
Sun Jan 7 18:59:46 EST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:93a3lp01kpg at news1.newsguy.com...

> For "grabbing the output", I assume you mean getting characters that the
> script is emitting to standard-output.

Yep, that's it.

> For that, it's somewhat simpler to
> do
> the 'output capture' in Python, with a StringIO object, then call its
> getvalue
> method to get the contents as a string.

Thank you very much, Alex. I had managed to solve the problem myself, but
your solution involves massively less code. Very helpful. (I made a Python
type in C++ and instantiated that in the python code, redirected sys.stdout
to it and got hold of the object and called it from C++ to get the string
after casting it to the C++ type, this is much easier.)

I am just playing around with extending/embedding Python to learn how to
interface C++ to Python and vice versa. As a suitable/interesting (to me
that is) project I choose to see how difficult it would be to make an isapi
extension (IIS) that processes url's that point to py files. If I could make
the ISAPI extension so that it could use cgi scripts written in python
without modification it would be neat.

I think my biggest problem is the multithreading and how that would affect
the interpreter. For the extension to work it is vital that each thread has
it's "own interpreter" so that code from the different threads aren't mixed
with each other. I have another posting that concerns this issue but I am
not sure if my requirements mandates using the Py_NewInterpreter function.






More information about the Python-list mailing list