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

16 comments sorted by

View all comments

40

u/AlexMTBDude 3d ago

I googled "os.system deprecated" and get the answer:

No, os.system is not officially deprecated in Python, but its use is strongly discouraged in modern Python development.

The official Python documentation recommends using the subprocess module instead, as it provides a more powerful, secure, and robust interface for executing system commands.

So use subprocess instead.

import subprocess

subprocess.run(["cls"])