示例:
[root@bogon ~]# python >>> import platform >>> platform.dist() ('redhat', '7.6', 'Maipo')
示例:
[root@bogon ~]# python >>> import platform >>> platform.linux_distribution() ('Red Hat Enterprise Linux Server', '7.6', 'Maipo')
注意:dist即将被linux_distribution取代。建议使用后者。
实例:
#!/usr/bin/env python #coding: utf-8 import platform def cg_is_redhat_6x(): try: os_vers = platform.linux_distribution() os_name = os_vers[0].lower() if os_name.find('centos', 0) == 0 or os_name.find('red hat', 0) == 0: if os_vers[1][0:2] == '6.': return True except: cg_print('EXECEPT! It\'s not clear whether Redhar/CentOS 6x.') return False return False