Heim  >  Artikel  >  Backend-Entwicklung  >  Python实现获取操作系统版本信息方法

Python实现获取操作系统版本信息方法

WBOY
WBOYOriginal
2016-06-06 11:24:091368Durchsuche

最近,想在我的YouMoney(http://code.google.com/p/youmoney/)里面增加提取用户操作系统版本信息。比如windows用户,可能要返回Windows XP ,或者Windows 2003, 苹果用户应该返回Mac OS X 10.5.8。用了很多办法,包括在mac系统里调用系统命令,取环境变量,等等。最后无意发现,原来python里里面有个platform模块就可以干这件事情。省事啊!

mac上这么干

代码如下:


localhost:~ apple$ python
Python 2.5.1 (r251:54863, Jun 17 2009, 20:37:34)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.mac_ver()
('10.5.8', ('', '', ''), 'i386')
>>> platform.version()
'Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386'
>>> platform.platform()
'Darwin-9.8.0-i386-32bit'
>>> platform.system()
'Darwin'
>>>


基本上用platform.platform()就足够了。如果是在windows上,专门还有个platform.win32_ver() 可用。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn