开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜