I know this is something that has been asked before, but I have tried most of what people have told me to do and none of it has worked. The most agreed upon method of clearing the last printed screen is to use \r
, but it hasn't really been working for me.
My code:
import time
import sys
frames = ["[ ]", "[= ]", "[== ]", "[=== ]", "[ ===]", "[ ==]", "[ =]", "[ ]", "[ =]", "[ ==]", "[ ===]", "[====]", "[=== ]", "[== ]", "[= ]"]
while True:
for frame in frames:
print('\r' frame, end='')
time.sleep(0.1)
The output ends up printing every single new iteration as a new line.
[ ]
[ =]
[ ==]
[ ===]
[====]
[=== ]
[== ]
[= ]
[ ]
[= ]
[== ]
[=== ]
[ ===]
[ ==]
[ =]
[ ]
[ =]
[ ==]
[ ===]
[====]
[=== ]
[== ]
[= ]
[ ]
[= ]
[== ]
[=== ]
[ ===]
[ ==]
[ =]
[ ]
[ =]
[ ==]
I'm not sure what mistake I am making but if someone could please enlighten me that would be amazing. Thank you.
(Some other information. I am using online-python.com to write this, and they are on version 3.8.5)
CodePudding user response:
As far as I can tell, this is a problem with the online IDE. I ran your code on a regular IDE (PyCharm Community) and it worked perfectly fine. I would consider using software installed on your PC. Pycharm is really beginner-friendly and I would fully recommend it.
CodePudding user response:
Just made a game using
import os
at the top
then
os.system('Clear')
just above the next print statement. Don't know if that's what you are trying to do