Maya's Python Print statement


I wrote a logger that outputs stdout/stderr (info, warning, error and debug) to a Qt Window that also output’s to a logging file.

The problem that I’m having now is that I’ve broken Maya’s print statement. Print output will only show up in the Qt Window that I have re-directed output too.

How do I reset Maya’s Script Editor to starting receiving output from print statements again?

NOTE: It’s only Python’s print statement that doesn’t work, everything else outputs (i.e., mel.eval(‘print “Hello World”’)


Since I was overwriting XStream and redefining stdout I needed to reset stdout to point to Maya’s output, but where is that? Well, the hint was staring me in the face, I just needed to find it; the answer was in (pymel’s logging system). There’s a function called _fixMayaOutput and they use it to reset their own logging system.


import sys
from maya import utils

# redefine sys.stdout
sys.stdout = utils.Output

# in order to use stdout 'write' requires a 'maya.Output' so we flush it
class MayaOutput(sys.stdout):
    def flush(*args, **kwargs):
        utils.Output = MayaOutput()
        sys.stdout = utils.Output

# initialize
log = MayaOutput()

# and flush, we're back to feeding output to the script editor

print("Hello World")


the original console is always available in sys.stdout


I’don know if anyone can read this reeply.
i run the code , in maya,but i got an error:

class MayaOutput(sys.stdout):
def flush(*args,**kwargs):
utils.Output = MayaOutput()
sys.stdout = utils.Output

Error: TypeError: file line 2: Error when calling the metaclass bases

file() argument 2 must be string, not tuple # 

why~? help~!!! please.