开发者

How to know the system is Debian or CentOS in Python?

开发者 https://www.devze.com 2023-03-04 17:30 出处:网络
I want to write some install scripts by python, it should know the OS to choose either apt command or yum command.

I want to write some install scripts by python, it should know the OS to choose either apt command or yum command.

It seems sys.开发者_运维技巧platform can tell 'win32' or the others, but how to know it is working on Debian or CentOS in Python?


The platform module in the standard library has what you want.

import platform
print platform.linux_distribution()


If you just need to know whether to use yum or apt, one approach is simply to pick one of those commands and try it. If it works, it works; if not, catch the exception and try the other command.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号