[Tutor] how to determine windows version

P.T. Waugh MA ptwaugh at earthlink.net
Sun Nov 9 00:18:19 EST 2003


Tim,

thanks for showing me how to 'fish'  =)

Patrick


At 12:16 AM 11/9/2003 -0500, you wrote:
>From: "P.T. Waugh MA" <ptwaugh at earthlink.net>
> > Hi all,
> >
> > Can't figure out how to determine the windows version my code is running
> > on.  I need to tell so I can determine where in the registry to look for
> > the location of a program.
> >
> > Thanks,
> >
> > Patrick
>
>Using my Windows XP pro machine, I tried this....
>
> >>> import sys
> >>> dir(sys)
>['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__',
>'__stdin__', '__stdout__', '_getframe', 'api_version', 'argv',
>'builtin_module_names', 'byteorder', 'call_tracing', 'callstats',
>'copyright', 'displayhook', 'dllhandle', 'exc_clear', 'exc_info',
>'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix',
>'executable', 'exit', 'exitfunc', 'getcheckinterval', 'getdefaultencoding',
>'getfilesystemencoding', 'getrecursionlimit', 'getrefcount',
>'getwindowsversion', 'hexversion', 'maxint', 'maxunicode', 'meta_path',
>'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform',
>'prefix', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace',
>'stderr', 'stdin', 'stdout', 'version', 'version_info', 'warnoptions',
>'winver']
>
>Hmm, a few of those look promising.  Let's see what they do.
>
> >>> sys.platform
>
>Not too helpful.
>
> >>> sys.version
>'2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)]'
>
>Ah, that tells me about Python.
>
> >>> sys.version_info
>(2, 3, 2, 'final', 0)
>
>About Python in a tuple.
>
> >>> sys.winver
>'2.3'
>
>Looks like that just again tells me about Python.
>
> >>> sys.getwindowsversion
><built-in function getwindowsversion>
>
>Maybe this is what we need, but it's not a string; it's a function.  Let's
>check the __doc__
>
> >>> sys.getwindowsversion.__doc__
>'getwindowsversion()\n\nReturn information about the running version of
>Windows.\nThe result is a tuple of (major, minor, build, platform,
>text)\nAll elements are numbers, except text which is a string.\nPlatform
>may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n'
>
>Yes, that seems like what we will need.
>
> >>> sys.getwindowsversion()
>(5, 1, 2600, 2, 'Service Pack 1')
>
>So I am using Windows 5.1.2600, which is NT/2000/XP based with Service Pack
>1.  It all checks out.
>
>Remember, dir(module) and __doc__ can be your friends.  If you can't
>remember what modules there are, try looking at
>http://www.python.org/doc/current/modindex.html
>
>  - Tim
>
>
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.536 / Virus Database: 331 - Release Date: 11/04/2003




More information about the Tutor mailing list