2024-05-28 19:44:55 发布
网友
我正在尝试在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 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')
试试这个:
请尝试以下代码:
怎么办platform.linux_发行版?在
相关问题 更多 >
编程相关推荐