os.name under Win32

Igor Kravtchenko igor at mekensleep.com
Wed Sep 13 06:12:13 EDT 2006


Hi again,

I get back to this old "thread".

sys.platform returns indeed "win32" under Windows.

os.name should return "posix" even under Windows if we are under Cygwin 
as Martin suggested.

Recently, someone advised me to use instead:
platform.system()

that returns only 3 different strings: Java, Linux or Windows.  End of 
story.

Is this not supposed to work better than sys.platform?
Indeed I'm pretty worried about having "win64" returned on further os 
like Windows Vista
and having our tests failing again.

Igor.



Fredrik Lundh wrote:

>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