简体   繁体   English

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

[英]Get Common OS name of Linux Python

I am trying to get Linux distro name like centos, fedora, ubuntu, SuSE etc in python. 我试图在python中获得Linux发行版名称,如centos,fedora,ubuntu,SuSE等。
I made use of platform module. 我利用了平台模块。
My code is 我的代码是

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

It gives me the desired output. 它给了我想要的输出。 But is there any simpler way other than this, or any module which gives me the name directly? 但是,除了此以外,还有其他更简单的方法或任何直接给我命名的模块吗?

Try this: 尝试这个:

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

what about platform.linux_distribution? 那platform.linux_distribution呢?

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

Try the following code: 尝试以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM