我有一个关于python编程的问题,假设我有一个循环,所以在这个循环中,我想标准输出写入3个变量在不同的行中。
例如:
while (True):
a += 0
b += 5
c += 10
sys.stdout.write("\routput1 = %d" % a)
sys.stdout.write("\routput2 = %d" % b)
sys.stdout.write("\routput3 = %d" % c)
所以在终端应该是这样的:
^{pr2}$
每一个输出都保持在行中并保持刷新。谢谢您!在
Tags:
对于Windows上的单行,可以执行
sys.stdout.write()
操作,然后编写光标移动'\b'
将光标移回行的开头。在在同一行上具有%progress指示符的复制文件函数的示例,使用此方法:
对于多行打印,Windows上的每个控制台窗口都是行数,列数。。。通常25行80列作为旧标准。在
您可以将光标移动到(y,x)位置,并在屏幕上打印字符串。在
y=线 x=列
示例代码:
然后,您可以通过将光标移动到适当的位置,然后使用给定的函数打印一个字符串,来打印多行。在
一个3行的例子:简单的方法是执行
os.system('CLS')
来清除屏幕,然后可以将光标移动到1,1
2,1
3,1
并重复,直到完成所有的处理。最后,不要忘记将光标移动到4,1
。当然,您可以选择控制台窗口的任何位置。在相关问题 更多 >
编程相关推荐