标准输出内容
在IDLE Shell输入如下代码<import sys
for i in range(3):
sys.stderr.write('hello')>
运行结果如下:
hello5
hello5
hello5,
接着输入<for i in range(3):
sys.stderr.write('hello,1')>
运行结果是:
hello,l7
hello,l7
hello,l7
我没搞明白的是:为何在每个输出后面都带个统计数据?
因为 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).
|
|----------------------------------------------------------------------
页:
[1]