来自python --help
:
-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
see man page for details on internal buffering relating to '-u'
手册页指出:
-u Force stdin, stdout and stderr to be totally unbuffered. On
systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file-object iterators (“for line in sys.stdin”) which is not influenced by this option. To work around this, you will want to use “sys.stdin.readline()” inside a “while 1:” loop.
Python以缓冲模式打开stdin,-out和-error流;它会读取或写入更大的块,将数据保留在内存中,直到达到阈值为止。-u
禁用这些缓冲区。
此外,python可以解释打开文件上的换行符,并将它们与本机平台换行符进行相互转换(文本模式)。该-u
选项禁用此转换,使您可以处理二进制数据,而不必担心\r\n
组合可能会发生什么。使用此功能打开文件时,相当于使用rb
或wb
模式open()
。