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

2024-05-28 19:44:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

import platform
version = platform.platform(aliased=0)
version = version.split('-with-',1)[1].split('-',1)[0]
print version

它给了我想要的输出。但是有没有比这更简单的方法,或者任何直接给我名字的模块呢?在


Tags: 模块代码import名称利用versionubuntulinux
3条回答

试试这个:

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

请尝试以下代码:

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

怎么办platform.linux_发行版?在

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

相关问题 更多 >

    热门问题