os independent temp dir?

Mark Hadfield m.hadfield at niwa.cri.nz
Thu May 10 02:09:14 CEST 2001


From: "Ben Hutchings" <ben.hutchings at roundpoint.com>
> > How about:
> >
> > >>> import os
> > >>> def getTemp():
> > ... for possible in ('temp','tmp','tmpdir'):
> > ... if os.environ.has_key( possible):
> > ... return os.environ[ possible ]
> > ...
> > >>> getTemp()
> > 'c:\\temp'
> > >>>
> >
> Unix environmental variable names are case-sensitive and are
> usually all-caps.

Meanwhile Windows environment variables are not case-sensitive, but *Python
dictionaries* are, so (since approx version 1.5) Python on Windows
translates all environment variables into upper-case entries in os.environ.
Therefore on Windows as well as Unix, the test above will only do what is
intended if it is written:

> > ... for possible in ('TEMP','TMP','TMPDIR'):

But as I said before, this test & others are already done for you inside the
tempfile module.

---
Mark Hadfield
m.hadfield at niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research


-- 
Posted from clam.niwa.cri.nz [202.36.29.1] 
via Mailgate.ORG Server - http://www.Mailgate.ORG



More information about the Python-list mailing list