Reliably detect Windows in Python

前端 未结 6 1362
半阙折子戏
半阙折子戏 2020-12-12 21:46

I\'m working on a couple of Linux tools and need to prevent installation on Windows, since it depends on FHS and is thus rendered useless on that platform. The platfor

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 22:16

    >>> import os
    >>> os.name
    'nt'
    

    "The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'." (c) http://docs.python.org/library/os.html#os.name

    import os
    if os.name == 'nt':
        #yourcodehere
    

提交回复
热议问题