Redirecting stdout to C/C++.

Jens Scheidtmann scheidtm at mx.uni-saarland.de
Mon Jan 21 18:03:56 CET 2002


Sebastian Haase wrote:
> (Quick Question:  Later I would like to redirect the stdout of python
> into some other c++ - stream   -- Anyone done that??? )

import sys
import yourModule

class MFCStdOut:
  def write(self, s)
    return yourModule.CallExtensionFunction(s)

sys.stdout = MFCStdOut()

as documented in ref.pdf (sys.stdout) and api.pdf (for extending python)
works for me. 

Jens

P.S.: When calling Py_Initialize() and Py_Finalize() in succession does
VC++ detect memory leaks?

--
Universität des Saarlandes
Technische Chemie
Jens Scheidtmann
Am Markt Zeile 3
66125 Saarbrücken-Dudweiler
Tel.: + 49 681 302 64139
Fax.: + 49 681 302 2343



More information about the Python-list mailing list