Python: What OS am I running on?

前端 未结 26 2046
野趣味
野趣味 2020-11-22 05:44

What do I need to look at to see whether I\'m on Windows or Unix, etc?

26条回答
  •  余生分开走
    2020-11-22 06:27

    How about a simple Enum implementation like the following? No need for external libs!

    import platform
    from enum import Enum
    class OS(Enum):
        def checkPlatform(osName):
            return osName.lower()== platform.system().lower()
    
        MAC = checkPlatform("darwin")
        LINUX = checkPlatform("linux")
        WINDOWS = checkPlatform("windows")  #I haven't test this one
    

    Simply you can access with Enum value

    if OS.LINUX.value:
        print("Cool it is Linux")
    

    P.S It is python3

提交回复
热议问题