python:在控制台上打印多行到位 [英] python : print the multiple lines on console in place

查看:86
本文介绍了python:在控制台上打印多行到位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制台上打印多行.像这样,

I want to print multiple lines on console in place. Like this,

AAAAAA

BBBBBB

但是,如果我使用 '\r' 在字符串上方打印,如下所示,

But, If I print above the strings using '\r' as below,

for i in range(10):
   time.sleep(1)
   print("AAAA\r", end='')
   time.sleep(1)
   print("BBBB\r", end='')

最后的结果就是这样

 BBBB

发生的事情是 AAAA->BBBB->AAAA->BBBB.....它不是这样打印的(就地!):

What's happening is AAAA->BBBB->AAAA->BBBB..... and it's not printing like this(IN PLACE!):

AAAA

BBBB

不喜欢这个

AAAA

BBBB

AAAA

BBBB

AAAA

BBBB

...

有什么解决办法吗?请帮帮我

Is there any solution about this? Please help me

推荐答案

这是你想要的吗..

for i in range(10):
    time.sleep(1)
    print("AAAAA\n\n")
    time.sleep(2)
    print("BBBBB\n\n")

这篇关于python:在控制台上打印多行到位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆