因为 write() 方法最后会返回实际上写入了多少个字符:
>>> help(sys.stderr)
Help on StdOutputFile in module idlelib.run object:
class StdOutputFile(StdioFile)
| StdOutputFile(shell, tags, encoding='utf-8', errors='strict')
|
| Method resolution order:
| StdOutputFile
| StdioFile
| io.TextIOBase
| _io._TextIOBase
| io.IOBase
| _io._IOBase
| builtins.object
|
| Methods defined here:
|
| writable(self)
| Return whether object was opened for writing.
|
| If False, write() will raise OSError.
|
| write(self, s)
| Write string to stream.
| Returns the number of characters written (which is always equal to
| the length of the string).
|
| ----------------------------------------------------------------------
|