Python implements a method to get operating system version information

  • 2020-05-05 11:28:04
  • OfStack

Recently, want to in my YouMoney (http: / / code. google. com p/youmoney /) increase in extracting user operating system version information. For example, windows users might return Windows XP, or Windows 2003, and apple users should return Mac OS X 10.5.8. Many methods are used, including calling system commands in mac system, taking environment variables, and so on. It turned out that there was an platform module in python that could do this. Save trouble!

mac does this


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'
>>>

Basically platform.platform () is enough. If you're on windows, there's also an platform.win32_ver ().


Related articles: