4

Currently I am 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 (eg: by using built-in Python API)?

>>> print _get_mac_ver()
10.6.3

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

1 Answer 1

8

True to the philosophy that python comes with batteries included, there is a module in the standard library to do this: 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.