Python: What OS am I running on?

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

    Check the available tests with module platform and print the answer out for your system:

    import platform
    
    print dir(platform)
    
    for x in dir(platform):
        if x[0].isalnum():
            try:
                result = getattr(platform, x)()
                print "platform."+x+": "+result
            except TypeError:
                continue
    

提交回复
热议问题