How to recognize Windows 10 using Python?

import platform 
if platform.release() == 'post2008Server' and platform.version() ==   '6.2.9200':
     print "It windows 8"

I used this before to recognize Windows 8. But it returns the same for Windows 10. So is there any other way to recognize it?

+4
source share
1 answer

In future versions of Python, everything works fine.

Python 3.5.1:

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'

Python 2.7.11

>>> import platform
>>> platform.release()
'10'
>>> platform.version()
'10.0.10240'

How about upgrading to at least 2.7.x?


Edit: As @Rogalski mentioned, you can always pass a command ver, and this should return the following regardless of the version of Python:

>>> import subprocess
>>> subprocess.Popen('ver', shell=True, stdout=subprocess.PIPE).communicate()[0]
'\r\nMicrosoft Windows [Version 10.0.10240]\r\n'
+4
source

All Articles