Portability guidelines (was Re: Tutorial suggestions)

Guido.van.Rossum@cwi.nl
Thu, 29 Sep 1994 16:52:47 +0100

> From: "Steven D. Majewski" <sdm7g@virginia.edu>
[...]
> A Python portability guide would be another nice addition:
> When I wrote that, I recall asking about what functions
> can be depended on to be in os, what the possible literal
> values for os.name are, etc. and getting some answers from
> Guido and others.
>
> Have the folks who ported Python to NT or OS/2 for example,
> paid attention to these details ? I wouldn't blame them if
> they didn't - I don't think they are prominently mentioned
> in a porting guide or anything.
>
> What string is returned by os.name on NT ? ( 'nt', 'NT', 'win32' ? )
> Does the dos windows version return 'win' or something
> to distinguish it from the vanilla dos port ?
>
> We need to know these exactly and case sensitively, 'cause
> people like me use them in tests and they may be needed
> in naming other conditionally imported modules.

No, no, no... You DON'T want to know the name of the operating
system.

I challenge you to find a situation where you need to know the name of
the operating system. Usually what you really want to know is
e.g. the pathname separator, or whether a particular module is
provided, or whether particular functionality in a module is provided,
or a particular external program.

You may think that particular funtionality is only available on one
platform, but everybody who used #ifdef SYSV / #ifdef BSD in their
Unix C code found that there are some systems that are neither SYSV
nor BSD -- some systems are hybrid, sometimes it's a compile time
option, sometimes a run-time option, and sometimes it's file-system
dependent!

Python has excellent possibilities to figoure out the availability of
modules (just try to import it and catch the ImportError exception --
or check sys.builtin_module_names, but watch out for dynamically
loaded modules!) and functions (hasattr(module, function)). The
pathname separator and other relevant things are exported by module
'os' (maybe os.path would've been a better place).

External programs are a bit different but then each user's system can
be set up differently so knowing the os name won't be enough anyway...

I have no idea what os.name on the dos windows version is -- I bet
it's 'dos' (like on the basic dos version) because from a Python
program's point of view about the only discernible difference is the
amount of memory available. (Hmm... that would also be a nice
parameter to make available...)

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>

PS: on NT, os.name is 'nt' (I think :-)