当前位置:首页 > 操作系统 > MacOs

从Python中查找MacOSX版本

目前我正在使用这个:

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

是否有更好的版本(例如:通过使用内置的Python API)?

<code>>>> print _get_mac_ver()
10.6.3
</code>

注意:我尝试了os.uname()[2],它在Snow Leopard系统上打印10.3.0.

解决方法:

秉承包含电池的python的理念,标准库中有一个模块可以做到这一点:平台.

特别参见`mac_ver()’ function

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

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐