这可能是我错过的一些愚蠢的事情,但它确实让我挂断了c
我正在编写的一个更大的项目(扩展)。
为什么是print "Hello, World!"
传球None
和额外的\n
到sys.stdout
这里?
>>> import sys
>>> class StdOutHook:
... def write(self, text):
... sys.__stdout__.write("stdout hook received text: %s\n" % repr(text))
...
>>> class StdErrHook:
... def write(self, text):
... sys.__stderr__.write("stderr hook received text: %s\n" % repr(text))
...
>>> sys.stdout = StdOutHook()
>>> sys.stderr = StdErrHook()
>>>
>>> def x():
... print "Hello, World!"
...
>>>
>>> print x()
stdout hook received text: 'Hello, World!'
stdout hook received text: '\n'
stdout hook received text: 'None'
stdout hook received text: '\n'
>>>