I have wanted for a long time to find out how to clear something like print(\"example\") in python, but I cant seem to find anyway or figure anything out.
pr
I think this is what you want to do:
take the cursor one line up and delete the line
this can be done like using the code below
import sys
import time
def delete_last_line():
"Use this function to delete the last line in the STDOUT"
#cursor up one line
sys.stdout.write('\x1b[1A')
#delete last line
sys.stdout.write('\x1b[2K')
########## FOR DEMO ################
if __name__ == "__main__":
print("hello")
print("this line will be delete after 2 seconds")
time.sleep(2)
delete_last_line()
####################################
import os
os.system('cls')
Or os.system('clear')
on unix (mac and linux). If you don't want the scroll up either, then you can do this:
os.system("printf '\033c'")
should get rid of scroll back too. Something that works on all systems:
import os
os.system('cls' if os.name == 'nt' else "printf '\033c'")
import os
os.system('clear')
It Works. Clears your thing Just Fine.
import time
Dots = "."
total = 0
count = 0
while count < 5:
if total<1:
print("[+]Saving" + Dots,end="")
total+=1
time.sleep(1)
print(Dots,end="")
This code works perfectly fine...
Well; i have a temporary way:-
print('Hey', end = '')
for i in range(4):
print('\b', end = '')
print('How is your day?')