# 方法一:platform.dist 示例: ```python [root@bogon ~]# python >>> import platform >>> platform.dist() ('redhat', '7.6', 'Maipo') ``` # 方法二:platform.linux_distribution 示例: ```python [root@bogon ~]# python >>> import platform >>> platform.linux_distribution() ('Red Hat Enterprise Linux Server', '7.6', 'Maipo') ``` 注意:dist即将被linux\_distribution取代。建议使用后者。 实例: ```python #!/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 ```