Suppress output to stdout/stderr in InteractiveInterpreter
robert.kern at gmail.com
Fri Apr 16 11:16:23 EDT 2010
On 2010-04-16 00:42 AM, Dave W. wrote:
>>> Think I'll start a new post with the subject: "Globally override
>>> built-in print function?"
>> Don't bother. Replacing sys.stdout is the right thing to do. It
>> won't interfere with the C++ streams...
> I'm not so certain. Won't the C++ host app share the same
> stdin/stdout/stderr file descriptors with the embedded Python
> interpreter? So there's at least the *potential* for a background
> C++ thread dedicated to processing Python commands (which redirect
> stdout) to interfere with, say, the main thread's log statements to
> stdout. Seems like I could wind up with log statements in my
> interpreter results.
No. Changing the object that the name sys.stdout refers to does not swap out the
underlying file descriptors.
> Anyway, that's why I've got this mild obsession with finding a way
> to capture output from the interpreter *without* redirecting
Not possible. Many things write directly to sys.stdout/sys.stderr.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list