0

I have this code:

print("Please wait, your question is loading...")
sleep(4)

I want to add another print() with text, which will replace the print() above after sleep(4).

How to do that? I am using the latest version Python 3.9.0

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Kladeon
  • 15
  • 4
  • 2
    Using `sys.stdout.write` can give you more control over what is written to the console. Such as, don't send a NL, then next send only CR to return cursor to beginning of same line. – Keith Oct 18 '20 at 09:25
  • @Keith. Only works in some consoles – Mad Physicist Oct 18 '20 at 09:30
  • @Tomerikoo add that as an answer. It should be the accepted one (although the question should be closed since it is a duplicate) – Abhinav Mathur Oct 18 '20 at 10:28
  • @AbhinavMathur Why would I add it as an answer if it is already answered? This question is a duplicate and shouldn't be answered. It should be deleted or marked as a duplicate as it is already answered somewhere else – Tomerikoo Oct 18 '20 at 10:32
  • Agreed. But since it hasn't been marked duplicated, and there is an incorrect answer marked as accepted, I suggested you put in the correct answer as well – Abhinav Mathur Oct 18 '20 at 10:35

2 Answers2

0

Once you print something, then to erase it, you have not other alternative else than clear the screen. In Windows use:

import os
os.system('cls')

And in linux call clear command. And then print other things.

Wasif
  • 14,755
  • 3
  • 14
  • 34
0

well you could do something like this:

from os import system
from time import sleep

print("whatever you want")
sleep(2)
 
system("cls") # if you are on linux then replace cls with clear
print("whatever you want")

system.clear allows you to clear everything on the console.