从Python查找MacOSX版本

2024-10-01 07:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

目前我正在使用这个:

def _get_mac_ver():
    import subprocess
    p = subprocess.Popen(['sw_vers', '-productVersion'], stdout=subprocess.PIPE)
    stdout, stderr = p.communicate()
    return stdout.strip()

是否有更好的版本(例如:使用内置的pythonapi)?在

^{pr2}$

注意:我尝试了在雪豹系统上打印10.3.0的os.uname()[2]。在


Tags: importgetreturnmacdefstderrstdoutsw
1条回答
网友
1楼 · 发布于 2024-10-01 07:32:11

遵循python自带电池的理念,在标准库中有一个模块可以实现这一点:platform。在

具体请参见`mac_ver()' function

>>> import platform
>>> platform.mac_ver()
('10.6.3', ('', '', ''), 'i386')
>>> print platform.mac_ver()[0]
10.6.3

相关问题 更多 >