Find Python MacOSX Version

I am currently using this:

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

Is there a better version (for example: using the Python built-in API)?

 >>> print _get_mac_ver() 10.6.3 

Note. I tried os.uname()[2] , which prints 10.3.0 on a Snow Leopard system.

+4
source share
1 answer

It is true that python comes with batteries turned on , there is a module for this in the module: platform .

See, in particular, the `mac_ver () 'function :

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

Source: https://habr.com/ru/post/1314134/


All Articles