Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recognize windows 10 using Python? [closed]

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

I have used this before to recognize Windows 8. But it's returning same for Windows 10. So is there any other way to recognize it ?

like image 392
Deepak Avatar asked Mar 29 '16 06:03

Deepak


1 Answers

With the following Python versions 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 mentioned by @Rogalski, you can always pipe the ver command, and this should return the following independently of the Python version:

>>> import subprocess
>>> subprocess.Popen('ver', shell=True, stdout=subprocess.PIPE).communicate()[0]
'\r\nMicrosoft Windows [Version 10.0.10240]\r\n'
like image 53
Kevin Sandow Avatar answered Oct 06 '22 00:10

Kevin Sandow