Dived a bit into the source code.
The output of sys.platform
and os.name
are determined at compile time. platform.system()
determines the system type at run time.
sys.platform
is specified as a compiler define during the build configuration.os.name
checks whether certain os specific modules are available (e.g.posix
,nt
, …)platform.system()
actually runsuname
and potentially several other functions to determine the system type at run time.
My suggestion:
- Use
os.name
to check whether it’s a posix-compliant system. - Use
sys.platform
to check whether it’s a linux, cygwin, darwin, atheos, etc. - Use
platform.system()
if you don’t believe the other sources.