Python: What OS am I running on?

前端 未结 26 1622
野趣味
野趣味 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:09

    Sample code to differentiate OS's using python:

    from sys import platform as _platform
    
    if _platform == "linux" or _platform == "linux2":
        # linux
    elif _platform == "darwin":
        # MAC OS X
    elif _platform == "win32":
        # Windows
    elif _platform == "win64":
        # Windows 64-bit
    

提交回复
热议问题