[Python-Dev] Portable and OS-dependent module idea/proposal/

Guido van Rossum guido@CNRI.Reston.VA.US
Fri, 20 Aug 1999 11:13:16 -0400


From: "Gordon McMillan" <gmcm@hypernet.com>

> Jack Jansen wrote:
> 
> > There's one slight problem with this: when you use functionality
> > that is partially portable, i.e. a call that is available on Windows
> > and Unix but not on the Mac.
> 
>  It gets worse, I think. How about the inconsistencies in POSIX 
> support among *nixes? How about NT being a superset of Win9x? How 
> about NTFS having capabilities that FAT does not? I'd guess there are 
> inconsistencies between Mac flavors, too.
> 
>  The Java approach (if you can't do it everywhere, you can't do it)
> sucks. In some cases you could probably have the missing
> functionality (in os) fail silently, but in other cases that would
> be a disaster. 

The Python policy has always been "if it's available, there's a
standard name and API for it; if it's not available, the function is
not defined or will raise an exception; you can use hasattr(os, ...)
or catch exceptions to cope if you can live without it."

There are a few cases where unavailable calls are emulated, a few
where they are made no-ops, and a few where they are made to raise an
exception uncoditionally, but in most cases the function will simply
not exist, so it's easy to test.

--Guido van Rossum (home page: http://www.python.org/~guido/)