简体   繁体   English

如何接收 Mac 的操作系统版本? 对于 Python 3.7

[英]How to receive OS version for Mac? For Python 3.7

First of all, sorry for this stupid question.首先,对不起这个愚蠢的问题。

I want to receive OS version for Mac by python command.我想通过 python 命令接收 Mac 的操作系统版本。 Awaiting for output like this:像这样等待 output :

MacOS Sierra (mine) version 10.12.6 MacOS Sierra (mine)版本 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')它可以由 os.system('sw_vers') 执行

sw_vers command will gives you this information, sw_vers命令将为您提供此信息,

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'

You can get it with builtin libraries:您可以使用内置库获得它:

>>> import platform
>>> platform.system()
'Darwin'
>>> platform.mac_ver()
('10.15.4', ('', '', ''), 'x86_64')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM