Print in one line dynamically

后端 未结 20 3195
梦谈多话
梦谈多话 2020-11-21 23:32

I would like to make several statements that give standard output without seeing newlines in between statements.

Specifically, suppose I have:

for it         


        
20条回答
  •  情书的邮戳
    2020-11-22 00:02

    change

    print item
    

    to

    print "\033[K", item, "\r",
    sys.stdout.flush()
    
    • "\033[K" clears to the end of the line
    • the \r, returns to the beginning of the line
    • the flush statement makes sure it shows up immediately so you get real-time output.

提交回复
热议问题