Is the OS win9x or winnt? How to detect it?

Tim Peters tim.one at comcast.net
Sun Mar 2 17:46:19 CET 2003


[Chen]
> Is it possible to detect whether the OS is win9x or winnt?
>
> I used os.name but it returns "winnt" even on win98se. While sys.platform
> returns "win32".

sys.getwindowsversion() is new in Python 2.3, and returns a 5-tuple of
values built from from calling the Win32 GetVersionEx() function.

Before 2.3, you have to do something trickier.  For example,

    version_string = os.popen("ver").read()

and then parse version_string, assuming the box's COMPSPEC points to a shell
that supports the VER command.






More information about the Python-list mailing list