How to detect Mac OS version using Python?

Viewed 13843

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!

5 Answers
Related