Gunakan sys.platform
. Anda dapat menemukan informasi selengkapnya di sini http://docs.python.org/library/platform.html
lihat di sini: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")
Anda dapat melihat repo github saya https://github.com/sk3pp3r/PyOS dan menggunakan skrip pyos.py
Saya biasanya hanya menggunakan ini:
import os
if os.name == 'nt':
pass # Windows
else:
pass # other (unix)
sunting:
Semoga menanggapi komentar Anda:
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' ) )