Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I detect different OS system

I am making a quiz game and I want to make it so that when ever you go to test mode it will clear your screen. I want the program to be compatible with UNIX and windows. I want it to make it so that if the system is windows, it runs cls in the terminal, and if your on Linux it runs clear. I have nothing wrong with my code, I just can find what I want to do online.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

os.name would return nt if your system is Windows, and posix if POSIX, so you can do it like this

import os
if os.name == 'nt':
    os.system('cls')
else:
    os.system('clear')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading