0

First of all, sorry for this stupid question.

I want to receive OS version for Mac by python command. Awaiting for output like this:

MacOS Sierra (mine) version 10.12.6

Version is the main goal.

I already tried to use platform and os modules, but not succeed.

Thank you!

EDIT:

It can be executable by os.system('sw_vers')

Vas23Vewe
  • 81
  • 2
  • 4
  • 15

2 Answers2

1

sw_vers command will gives you this information,

ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G3020

Since you are interested in getting version, do string formatting.

>>> import commands
>>> output = commands.getoutput('sw_vers')
>>> version = output.split('\n')[1].split(':\t')[1]
>>> version
'10.14.6'
1

You can get it with builtin libraries:

>>> import platform
>>> platform.system()
'Darwin'
>>> platform.mac_ver()
('10.15.4', ('', '', ''), 'x86_64')
Philippe
  • 20,025
  • 2
  • 23
  • 32