Can python detect which OS is it running under?

Use sys.platform. You can find more information here http://docs.python.org/library/platform.html


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


I usually just use this:

import os
if os.name == 'nt':
    pass # Windows
else:
    pass # other (unix)

edit:

Hopefully in response to your comments:

from time import strftime
import os

if os.name == 'nt': # Windows
    basePath = 'C:\\working\\'
else:
    basePath = '/working/'

Fn = '%sSetup%s.csv' % ( basePath, strftime( '%y%m%d' ) )