简体   繁体   English

python:在控制台上打印多行

[英]python : print the multiple lines on console in place

I want to print multiple lines on console in place. 我想在控制台上打印多行。 Like this, 像这样,

AAAAAA

BBBBBB

But, If I print above the strings using '\\r' as below, 但是,如果我使用'\\r'打印字符串,如下所示,

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

The final result is just like this 最终的结果是这样的

 BBBB

What's happening is AAAA -> BBBB -> AAAA -> BBBB ..... and it's not printing like this(IN PLACE!): 发生的事情是AAAA - > BBBB - > AAAA - > BBBB .....并且它不是这样打印的(IN PLACE!):

AAAA

BBBB

Not Like this 不喜欢这个

AAAA

BBBB

AAAA

BBBB

AAAA

BBBB

...

Is there any solution about this? 对此有什么解决方案吗? Please help me 请帮我

is this what you want .. 这是你想要的吗 ..

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

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

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