Alex Alex - 1 month ago 5
Python Question

Python - Remove and Replace Printed items

[Using Python 3.2]
I was wondering if it was possible to remove items you have printed in python, not from the python gui but from the command propt.
e.g.

a = 0
for x in range (0,3):
a = a + 1
b = ("Loading" + "." * a)
print (a)


so it prints

>>>Loading
>>>Loading.
>>>Loading..
>>>Loading...


But, My problem is I want this all on one line, and for it it remove it self when somthing else comes along. so instead of going, "loading", "loading.", "loa.... I want it to got "Loading.", then it removes what is on the line and replaces it with "Loading.." and then removes "Loading.." and replaces it (on the same line) with "Loading...". Its kinda hard to discribe.

p.s
I have tried to use the Backspace charactor but it doesnt seem to work ("\b")

Thanks

Answer

Just use CR to go to beginning of the line.

import time
for x in range (0,5):  
    b = "Loading" + "." * x
    print (b, end="\r")
    time.sleep(1)
Comments