简体   繁体   English

更新多条输出线

[英]Updating multiple output lines

So I am trying to use sys.stdout.write() to rewrite the current line it is on and replace it with different text. 因此,我尝试使用sys.stdout.write()重写当前行,并将其替换为其他文本。 But I want this to happen for multiple lines of output. 但是我希望这种情况在多行输出中发生。

  # 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()

I tried this but every time it hits the \\n it will indefinately increase the numbers of lines without clearing everything. 我尝试了此操作,但是每次它到达\\ n时,都会无限增加行数,而不会清除所有内容。

stdout\\stderr don't work like that. stdout \\ stderr不能那样工作。 You can send control characters to your terminal to delete characters but once a line is sent it's basically fixed. 您可以将控制字符发送到终端以删除字符,但是一旦发送一行,它就基本固定了。

What you actually need is ncurses which gives you much more control over the display and cursor position when writing to a terminal. 您实际需要的是ncurses ,它可以使您在写入终端时更好地控制显示和光标位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM