[Python-ideas] Determine Windows version in platform module

Mathias Panzenböck grosser.meister.morti at gmx.net
Fri Dec 27 22:03:09 CET 2013


On 12/27/2013 07:48 PM, Giampaolo Rodola' wrote:
>
> On Fri, Dec 27, 2013 at 7:38 PM, M.-A. Lemburg <mal at egenix.com <mailto:mal at egenix.com>> wrote:
>
>     On 27.12.2013 19:18, Giampaolo Rodola' wrote:
>      > Today I was looking for a way to determine whether I was on Windows >=
>      > Vista and couldn't find anything so I came up with this [1].
>      >
>      > That led me to think about platform module.
>      > Honestly I can't see the usefulness of it as it doesn't give you any usable
>      > API to figure out what platform version you're on.
>
>     Have you had a look at the documentation ?
>
>     http://docs.python.org/2.7/library/platform.html?highlight=platform#windows-platform
>
>
> Yes, on Windows XP I get a tuple like this:
>
> ('XP', '5.1.2600', 'SP3', 'Uniprocessor Free')
>
> On Windows 7:
>
> ('7', '6.1.7600', '', 'Multiprocessor Free')
>
> Neither of those are helpful to make assumptions such as "if I'm on Windows >= XP with SP3: do something".
> The real deal would be dealing with a tuple of integers in order to use comparison operators, similarly to sys.version_info:
>
> if sys.version_info >= (3, 0):
>       # py3-specific code
>
>

What about this?:

     if tuple(int(v) for v in platform.win32_ver[1].split(".")) >= (5,1,2600):
         ...


More information about the Python-ideas mailing list