I wish to disable the ability to run my program on certain Windows operating systems to prevent certain issues I can't replicate in newer versions. I would like to prevent running it on Windows XP, Vista, and eventually, 7.
How can I achieve this? For a little while I used an if statement with _platform but that did not work well or efficiently.
You can use sys.getwindowsversion
:
import sys
ver = sys.getwindowsversion()
if ver.major == 6 and ver.minor == 1:
print('Windows 7')
elif ver.major == 6 and ver.minor == 0:
print('Windows Vista')
elif ver.major == 5 and ver.minor == 0:
print('Windows XP')
Version numbers taken from this page .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.