Jak sprawdzić, czy system operacyjny jest Vista w Pythonie?
Jak w najprostszy możliwy sposób rozróżnić Windows XP i Windows Vista, używając Pythona i pywin32lub wxPython?
Zasadniczo potrzebuję funkcji, która zwróci True iff bieżący system operacyjny To Vista:
>>> isWindowsVista()
True
25
5 answers
Python ma piękny moduł 'platform', który Ci pomoże.
>>> import platform
>>> platform.win32_ver()
('XP', '5.1.2600', 'SP2', 'Multiprocessor Free')
>>> platform.system()
'Windows'
>>> platform.version()
'5.1.2600'
>>> platform.release()
'XP'
Uwaga: Jak wspomniano w komentarzach, właściwe wartości mogą nie być zwracane podczas używania starszych wersji Pythona.
41
Author: monkut,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-25 06:57:25
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-25 06:57:25
Rozwiązanie stosowane w skręconych, które nie wymagają pywin32:
def isVista():
if getattr(sys, "getwindowsversion", None) is not None:
return sys.getwindowsversion()[0] == 6
else:
return False
Zauważ, że będzie również pasował do systemu Windows Server 2008.
8
Author: Thomas Hervé,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-13 07:55:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-13 07:55:47
Najprostszym rozwiązaniem jakie znalazłem jest to:
import sys
def isWindowsVista():
'''Return True iff current OS is Windows Vista.'''
if sys.platform != "win32":
return False
import win32api
VER_NT_WORKSTATION = 1
version = win32api.GetVersionEx(1)
if not version or len(version) < 9:
return False
return ((version[0] == 6) and
(version[1] == 0) and
(version[8] == VER_NT_WORKSTATION))
8
Author: DzinX,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-17 11:34:50
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-01-17 11:34:50
Pomysł z http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html może pomóc, co w zasadzie może odpowiedzieć na twoje pytanie:
win_version = {4: "NT", 5: "2K", 6: "XP"}[os.sys.getwindowsversion()[0]]
print "win_version=", win_version
0
Author: Deming,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-09 14:24:42
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-09 14:24:42
import platform
if platform.release() == "Vista":
# Do something.
Lub
import platform
if "Vista" in platform.release():
# Do something.
0
Author: Boštjan Mejak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-02 18:08:39
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-02 18:08:39