美文网首页
利用 Python 查看系统发行版

利用 Python 查看系统发行版

作者: Monsty | 来源:发表于2018-05-15 09:50 被阅读0次

    偶然看到 Python 有一个 platform 标准库。利用这个库可以方便地查看系统发行版:

    #!/usr/bin/python2
    import platform
    print platform.dist()
    # ('centos', '7.4.1708', 'Core')
    

    在 shell 中可以这样
    python2 -c 'import platform as p; print p.dist()'
    怎么样是不是很方便,因为绝大部分 Linux 系统都自带 Python2,再也不用纠结 lsb_release 啥的有没有安装啦~

    注:当然如果可能是 Windows 的话,用 platform.platform() 判断平台就行了。但由于不是 tuple 的形式,需要自己处理字符串解析。

    #!/usr/bin/python2
    import platform
    print platform.platform()
    # Linux-3.10.0-693.17.1.el7.x86_64-x86_64-with-centos-7.4.1708-Core
    # OR
    # Windows-10-10.0.16299-SP0
    

    相关文章

      网友评论

          本文标题:利用 Python 查看系统发行版

          本文链接:https://www.haomeiwen.com/subject/pfhedftx.html