如何在 Python 中检查操作系统是否为 Vista? [英] How to check if OS is Vista in Python?

查看:34
本文介绍了如何在 Python 中检查操作系统是否为 Vista?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以最简单的方式区分 Windows XP 和 Windows Vista,使用 Python 和 pywin32 还是 wxPython?

本质上,我需要一个函数,当当前操作系统是 Vista 时,该函数将返回 True:

<预><代码>>>>isWindowsVista()真的

解决方案

Python 有可爱的平台"模块可以帮助您.

<预><代码>>>>进口平台>>>platform.win32_ver()(XP"、5.1.2600"、SP2"、无多处理器")>>>平台.系统()'视窗'>>>平台.版本()'5.1.2600'>>>平台.release()'经验'

注意:如评论中所述,使用旧版本的 python 时可能不会返回正确的值.

How, in the simplest possible way, distinguish between Windows XP and Windows Vista, using Python and pywin32 or wxPython?

Essentially, I need a function that called will return True iff current OS is Vista:

>>> isWindowsVista()
True

解决方案

Python has the lovely 'platform' module to help you out.

>>> import platform
>>> platform.win32_ver()
('XP', '5.1.2600', 'SP2', 'Multiprocessor Free')
>>> platform.system()
'Windows'
>>> platform.version()
'5.1.2600'
>>> platform.release()
'XP'

NOTE: As mentioned in the comments proper values may not be returned when using older versions of python.

这篇关于如何在 Python 中检查操作系统是否为 Vista?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆