os.name under Win32

Fredrik Lundh fredrik at pythonware.com
Fri Sep 1 11:49:13 EDT 2006


Igor Kravtchenko wrote:

> We have an application using Python that is intended to work both under 
> Win32 and Linux.
> Since some parts of the code need to be different depending whether we 
> are under Win32
> or Linux, we use the traditional:
> 
> if os.name == "posix":
>   some Linux code
> else:
>   some Win32 code

the usual thing to test for is sys.platform, not os.name.

    if sys.platform == "win32":
        some win32 code (or win64 code)
    else:
        some linux code

> However, we have noticed that under some circumstances, in some cases, 
> in some computers under Windows XP Family that the "posix" code was
 > executed causing of course a crash.

sounds weird.  have you checked your code so you don't assign to os.name 
somewhere, by accident?

</F>




More information about the Python-list mailing list