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.
JavaScript
x
3
1
print("Hey")
2
>Hey
3
Now I need to clear it, and write some new text.
JavaScript
1
2
1
print("How is your day?")
2
It would print.
Hey
JavaScript
1
2
1
>How is your day?
2
But I want to clear the “Hey” so the user shouldnt look at both at same time, and it looks kinda messy.
Advertisement
Answer
JavaScript
1
3
1
import os
2
os.system('cls')
3
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 '33c'")
should get rid of scroll back too. Something that works on all systems:
JavaScript
1
3
1
import os
2
os.system('cls' if os.name == 'nt' else "printf '33c'")
3