Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
终端python 2.7上相同位置的动态更新文本_Python_Python 2.7_Dynamic_Console Output - Fatal编程技术网

终端python 2.7上相同位置的动态更新文本

终端python 2.7上相同位置的动态更新文本,python,python-2.7,dynamic,console-output,Python,Python 2.7,Dynamic,Console Output,我的程序是用Python2.7编写的,我想做一个动态更新。输出在表视图中,有数百个字符。然而,我发现了一个非常好的答案,它压碎了100多个字符(正如文章中承诺的那样)。而且,我不知道这个表有多少行,它是动态变化的。此外,我不想使用诅咒,因为我希望输出像运行“regular”命令一样内联在控制台中 输出示例: 我试图避免: 您可以使用ANSI代码上移多行。它应该在linux中工作: import time import sys for i in range(0, 100): # prin

我的程序是用Python2.7编写的,我想做一个动态更新。输出在表视图中,有数百个字符。然而,我发现了一个非常好的答案,它压碎了100多个字符(正如文章中承诺的那样)。而且,我不知道这个表有多少行,它是动态变化的。此外,我不想使用诅咒,因为我希望输出像运行“regular”命令一样内联在控制台中

输出示例:

我试图避免:


您可以使用ANSI代码上移多行。它应该在linux中工作:

import time
import sys

for i in range(0, 100):
  # print 4 lines
  print ("line 1\nline 2\nline 3")
  print (str(i))
  time.sleep(0.2)
  sys.stdout.write("\033[4A") # go up 4 lines

它将在一些终端工作。它在窗户腻子里起作用。如果在putty终端中返回的行数超过行数,它将不允许您向上滚动文本,而是将光标移动到第一个可见行

您希望此程序在什么操作系统上运行?操作系统为ubuntu16.04谢谢您的回答。它总是将密钥放置器放在最上面,即使该命令在屏幕的底部运行,而且我已经多次更改了行数:从1行更改为表长度+我不确定它是ubuntu相关的还是ssh终端
+------+--------------+-------------+
| Type |  IP Address  |    Status   |
+------+--------------+-------------+
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
+------+--------------+-------------+
+------+--------------+-------------+
| Type |  IP Address  |    Status   |
+------+--------------+-------------+
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
+------+--------------+-------------+
+------+--------------+-------------+
| Type |  IP Address  |    Status   |
+------+--------------+-------------+
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  aa  | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
| cccc | 10.11.10.10  | in Progress |
|  bb  | 10.11.10.10  | in Progress |
+------+--------------+-------------+
import time
import sys

for i in range(0, 100):
  # print 4 lines
  print ("line 1\nline 2\nline 3")
  print (str(i))
  time.sleep(0.2)
  sys.stdout.write("\033[4A") # go up 4 lines