获取Linux Python的通用操作系统名称

获取Linux Python的通用操作系统名称,python,linux,Python,Linux,我正在尝试用python获得Linux发行版名称,如centos、fedora、ubuntu、SuSE等。 我使用了平台模块。 我的代码是 import platform version = platform.platform(aliased=0) version = version.split('-with-',1)[1].split('-',1)[0] print version 它给了我想要的输出。但是除了这个,还有其他更简单的方法吗?或者任何模块直接给我起名字吗?试试这个: >&

我正在尝试用python获得Linux发行版名称,如centos、fedora、ubuntu、SuSE等。
我使用了平台模块。
我的代码是

import platform
version = platform.platform(aliased=0)
version = version.split('-with-',1)[1].split('-',1)[0]
print version
它给了我想要的输出。但是除了这个,还有其他更简单的方法吗?或者任何模块直接给我起名字吗?

试试这个:

>>> import platform
>>> platform.linux_distribution()
('Red Hat Enterprise Linux Server', '6.6', 'Santiago')
试试这个:

>>> import platform
>>> platform.linux_distribution()
('Red Hat Enterprise Linux Server', '6.6', 'Santiago')

platform.linux\u发行版怎么样

In [1]: import platform                                                                                                                                                                                                                                                                                                 
In [2]: platform.linux_distribution()                                                                                                                         
Out[2]: ('Fedora', '21', 'Twenty One')                                                                                                                        

platform.linux\u发行版怎么样

In [1]: import platform                                                                                                                                                                                                                                                                                                 
In [2]: platform.linux_distribution()                                                                                                                         
Out[2]: ('Fedora', '21', 'Twenty One')                                                                                                                        

请尝试以下代码:

>>> import os
>>> cmd = "lsb_release -si"
>>> os.system(cmd)
Ubuntu

请尝试以下代码:

>>> import os
>>> cmd = "lsb_release -si"
>>> os.system(cmd)
Ubuntu

它适用于大多数发行版。但我不知道为什么我在Redhat中出错。>>platform.platform(别名=0)'Linux-2.6.18-128.6om-x86_64-with-redhat-7-Moonshine'>>>platform.Linux_distribution()回溯(最近一次调用):文件“”,第1行,在AttributeError:'module'对象没有属性'Linux_distribution'@sudheeshshetty,你的python版本是什么,你能发布dir(platform)的输出吗,我在dir(平台)中看不到linux_发行版。虽然当我粘贴错误时,我得到了另一个选择。i、 e platform.dist()。它适用于大多数发行版。但我不知道为什么我在Redhat中出错。>>platform.platform(别名=0)'Linux-2.6.18-128.6om-x86_64-with-redhat-7-Moonshine'>>>platform.Linux_distribution()回溯(最近一次调用):文件“”,第1行,在AttributeError:'module'对象没有属性'Linux_distribution'@sudheeshshetty,你的python版本是什么,你能发布dir(platform)的输出吗,我在dir(平台)中看不到linux_发行版。虽然当我粘贴错误时,我得到了另一个选择。i、 e platform.dist()。