Python: What OS am I running on?

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

    I am late to the game but, just in case anybody needs it, this a function I use to make adjustments on my code so it runs on Windows, Linux and MacOs:

    import sys
    def get_os(osoptions={'linux':'linux','Windows':'win','macos':'darwin'}):
        '''
        get OS to allow code specifics
        '''   
        opsys = [k for k in osoptions.keys() if sys.platform.lower().find(osoptions[k].lower()) != -1]
        try:
            return opsys[0]
        except:
            return 'unknown_OS'
    

提交回复
热议问题