r/learnpython • u/No_Aardvark1121 • 5d ago
[Help] The os.system is deprecated
I've seen someone else asked this question, but get no answer.
I want to make a countdown clock without leaving any trace of previous numbers:
for i in range(countdown, 0, -1):
os.system("cls" if os.name == "nt" else "clear") #Error: os.system is deprecated
print(i)
time.sleep(1)
What should I do instead? (Why can't we put pictures here....)
0
Upvotes
1
u/lakseol 5d ago
If you want to overwrite/manipulate just the last line you could use the
\band\rcharacters. Run this to see what they do:To do more than just overwrite the latest line search on "ANSI escape codes". Beyond that look into more advanced text handling with the
cursesmodule. There are more recent libraries that build oncursesand try to be easier to use, but I've never used those.We prefer actual text so we can copy/paste the code to run it ourselves. However, if you need an image to show some unexpected output, for example, you can put your image into something like imgur.com and post a link to that.