Re: Portability guidelines (was Re: Tutorial suggestions)

Steven D. Majewski (sdm7g@virginia.edu)
Thu, 29 Sep 1994 12:44:16 -0400 (EDT)

On Thu, 29 Sep 1994 Guido.van.Rossum@cwi.nl wrote:

> > 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.
> >
>
> 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 be right. I looked at that code and then at the library
reference manual, and found what I needed was os.pardir & os.curdir -
the current and parent directory string ( to be excluded in
recursive processing. ) I was expecting it to be in os.path,
not os, so I missed it.

I don't agree that you don't EVER need the name, but I do agree
that when you do need it, it should be kept hidden. You can't
always do all of you conditional code with try/expect failure.
That works when the module is either there or not. But if there
might be one implementation for the mac and one for dos and one
for unix, etc. then binding those names in statically limits
you to the ones you knew about at the time. ( But using os.name
dynamically means you DON'T have to know the possible set of
values, which is a different case from using 'if os.name == "dos"',
which is what I had in the 'find' code. )

So - you're right Guido, but I think *your* point helps make *my*
point that a tutorial on how to write portable python programs is a
good idea. ( I don't think it's hard - it's just not necessarily
obvious) I'll be happy to fix that part of find.py, and resubmit
it as an example, if you and others are willing to critique it,
so it *can* be a proper example of how to do it.

-- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU> --
-- UVA Department of Molecular Physiology and Biological Physics --
-- Box 449 Health Science Center Charlottesville,VA 22908 --
[ "Cheese is more macho?" ]