If you use end="\r"
in print()
then it will not go to next line but it will move to beginning of line - and then you can write again in the same line.
import time
print("Loading", end="\r")
time.sleep(1)
print("Loading.", end="\r")
time.sleep(1)
print("Loading..", end="\r")
time.sleep(1)
print("Loading...", end="\r")
time.sleep(1)
print() # move to next line
And this can be useful when you have to change text in line.
But for adding dots it is simpler to use end=""
to write in the same line
import itme
print("Loading", end="")
for _ in range(3):
time.sleep(1)
print(".", end="")
print() # move to next line
This method is used by some modules to draw progressbar
BTW:
You can also \r
and end=""
to keep cursor at the end of line
import time
print("\rLoading", end="")
time.sleep(1)
print("\rLoading.", end="")
time.sleep(1)
print("\rLoading..", end="")
time.sleep(1)
print("\rLoading...", end="")
time.sleep(1)
print() # move to next line
If new text is shorter than older text then you should write spaces at the end to remove previous text.
import time
print("\r....", end="")
time.sleep(1)
print("\r... ", end="")
time.sleep(1)
print("\r.. ", end="")
time.sleep(1)
print("\r. ", end="")
time.sleep(1)
print("\r ", end="")
print() # move to next line
If you want to display other text at the same time then you may need to use module like curses, urwind, npyscreen which can use special codes to move cursor in differen places in (some) terminals.