Framester
Framester

Reputation: 35461

How to do partial carriage return

I want to replace the cmd output of my Python script, without overwriting the first three characters of the line. Here is what I mean:

How I want it:

>>>ID1 downloading
>>>ID1 converting
>>>ID1 finished

With /r:

>>>ID0 downloading
>>>converting
>>>finished

Upvotes: 0

Views: 166

Answers (2)

Abhijit
Abhijit

Reputation: 63737

Try this. But this may not work in IDLE.

from time import sleep
from sys import stdout
stdout.write("\r%s" % "ID1 downloading")
stdout.flush()
sleep(1)
stdout.write("\r%s" % "ID1 converting ")
stdout.flush()
sleep(1)
stdout.write("\r%s" % "ID1 done       ")
stdout.write("\r  \r\n") # clean up

Upvotes: 0

Karl Knechtel
Karl Knechtel

Reputation: 61515

This isn't fundamentally a Python question; it's a standard output question.

The standard output doesn't work that way. The simplest thing is to just rewrite "ID1".

Otherwise you will need to move to something more advanced: either console-specific formatting commands (like ANSI), or a library like curses.

Upvotes: 4

Related Questions