这段代码在Windows和Linux之间输出不同的字符串。
test.py:
print(";".join([str(i) for i in range(10000)]))
平台:x86_64 Linux 4.4.0-17763-Microsoft
Python版本:3.7.2
终端:bash,fish
简要输出:
$ python --version
Python 3.7.2
$ python test.py
0;1;2;3;4;5;6....9997;9998;9999
$ python -u test.py
0;1;2;3;4;5;6....9997;9998;9999
平台:Windows 10 1809
Python 版本:3.6.8、3.7.0、3.7.2
终端:cmd、powershell
简略输出:
./python --version
Python 3.6.8
./python test.py
0;1;2;3;4;5;6....9997;9998;9999
./python -u test.py
0;1;2;3;4;5;6....2663;2664;2665;26
./python --version
Python 3.7.0
./python test.py
0;1;2;3;4;5;6....9997;9998;9999
./python -u test.py
0;1;2;3;4;5;6....2663;2664;2665;26
./python --version
Python 3.7.2
./python test.py
0;1;2;3;4;5;6....9997;9998;9999
./python -u test.py
0;1;2;3;4;5;6....2663;2664;2665;26
因此,为什么在Windows中使用
-u
参数会导致输出被截断(只显示从0
到2666
)?(当使用
python -u test.py > a.txt
将输出重定向到文件时,它可以正常工作。)也许是缓冲的原因?
maxline
是什么意思?是 Windows 的一个常量吗?当没有缓冲区时,stdout
实际上是做什么的?我在哪里可以找到更多相关信息? - OhYee