[Python-Dev] Re: Recommended way to tell platform
"Martin v. Löwis"
martin at v.loewis.de
Sun Aug 8 09:02:21 CEST 2004
Guido van Rossum wrote:
> I still prefer hasattr(<module>, <attribute>) whenever applicable,
> e.g. preferring hasattr(os, 'fork') over os.name=='posix' (or
> os.name!='nt' :-), but sometimes that's not possible.
>
> What should be the preferred way? (It may be impossible to say
> because there are different use cases, but probably one of the most
> important cases is simply distinguishing Windows from the rest -- how
> should that be done?)
Precisely that: impossible to say. In most cases, you should not test
for the platform, but just use the platform functionality, and fall back
to something else if it isn't present.
However, to reliably distinguish Windows from the rest, check whether
os.platform is "win32".
Regards,
Martin
More information about the Python-Dev
mailing list