Which OS?

Matt Gerrans mgerrans at mindspring.com
Wed Jul 10 01:42:33 EDT 2002


I suppose you are running PythonDos on DOS and regular Python on Windows,
but for some reason don't know which you are running at runtime.   I think
sys.platform will be adequate in your case, but here are a couple other
tricks, for good measure:

If you try to import any of the win32 extensions on windows, then that
should tell you; something like this:

inPlainOldDos = 1
try:
   import win32ui
   inPlainOldDos = 0
except:
   win32ui.MessageBox( 'You are not running on Windows and your script has
just crashed.')

(sorry, I couldn't resist: of course you will do something intelligent in
the exception handler, unlike me)

Another thing you can do is check for the 'windir' environment variable:

import os
if 'WINDIR' in os.environ:
   doWindowsStuff()
else:
   doDosStuff()


> ... Any form of reproduction, or further dissemination of this
> email is strictly prohibited.

Oh my, sounds like Google and a lot of other web-crawlers -- not to mention
servers in general -- are in big trouble now!





More information about the Python-list mailing list