因此,我尝试使用sys.stdout.write()重写它所在的当前行,并用不同的文本替换它。但我希望在多行输出中发生这种情况。
# I am looking at having 2 lines with changing values in them that will keep over writing themselves without moving any further down.
import sys
for i in range(10):
sys.stdout.write("\r" + "Hello" + str(i) + "\n + "Hello" + str(i) * 2)
sys.stdout.flush()我试过了,但每次命中时,它都会无限期地增加行数,而不会清除所有内容。
发布于 2017-02-02 20:48:05
stdout\stderr不是这样工作的。你可以发送控制字符到你的终端来删除字符,但是一旦发送了一行,它基本上就被修复了。
你真正需要的是ncurses,它能让你在写入终端时更好地控制显示和光标位置。
https://stackoverflow.com/questions/41999044
复制相似问题