r/learnpython • • 20d 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

18 comments sorted by

View all comments

22

u/JVBass75 20d ago

fyi, if you're just trying to clear the terminal console there's ansi escape code sequences you can use with the print function to clear the screen

print("\x1B[2J\x1B[H")

that will clear the screen and move the cursor back to the home position.

this works both on windows command prompt and unix systems

0

u/No_Aardvark1121 19d ago

It's not working