Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can python detect which OS is it running under?

Can python detect OS and then contruct a if/else statement for File System.

I would need to replace C:\CobaltRCX\ in Fn string with the FileSys string.

import os.path, csv
from time import strftime

if os.path.?????:## Windows
   FileSys = r"C:\\working\\" 
else:   ##linux   
   FileSys = r"\\working\\" 

y=(strftime("%y%m%d"))
Fn = (r"C:\\working\\Setup%s.csv" %y)
like image 433
Merlin Avatar asked Jan 17 '11 23:01

Merlin


1 Answers

see here: https://stackoverflow.com/a/58689984/3752715

import platform 
plt = platform.system()

if   plt == "Windows":   print("Your system is Windows")
elif plt == "Linux":     print("Your system is Linux")
elif plt == "Darwin":    print("Your system is MacOS")
else:                    print("Unidentified system")

you can see my github repo https://github.com/sk3pp3r/PyOS and use pyos.py script

like image 91
Haim Cohen Avatar answered Sep 22 '22 16:09

Haim Cohen