mac如何查看python版本,如何使用Python检测Mac OS版本?

My application is assumed to be running on a Mac OS X system. However, what I need to do is figure out what version of Mac OS (or Darwin) it is running on, preferably as a number. For instance,

"10.4.11" would return either 10.4 or 8

"10.5.4" would return 10.5 or 9

"10.6" would return 10.6 or 10

I found out that you could do this, which returns "8.11.0" on my system:

import os

os.system("uname -r")

Is there a cleaner way to do this, or at least a way to pull the first number from the result? Thanks!

解决方案>>> import platform

>>> platform.mac_ver()

('10.5.8', ('', '', ''), 'i386')

As you see, the first item of the tuple mac_ver returns is a string, not a number (hard to make '10.5.8' into a number!-), but it's pretty easy to manipulate the 10.x.y string into the kind of numbers you want. For example,

>>> v, _, _ = platform.mac_ver()

>>> v = float('.'.join(v.split('.')[:2]))

>>> print v

10.5

If you prefer the Darwin kernel version rather than the MacOSX version, that's also easy to access -- use the similarly-formatted string that's the third item of the tuple returned by platform.uname().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值