python 判斷作業系統型別

二月雪發表於2024-08-19
import sys
run_system = None


if sys.platform.startswith('linux'):
    # print('當前系統為 Linux')
    run_system = 'linux'
elif sys.platform.startswith('win'):
    # print('當前系統為 Windows')
    run_system = 'windows'
elif sys.platform.startswith('darwin'):
    # print('當前系統為 macOS')
    run_system = 'macOS'
else:
    # print('無法識別當前系統')
    run_system = "unknown"


if __name__ == '__main__':
    print(run_system)

相關文章