4 ms·
What's a bit unusual about Python is that it tries all three environment variables on every OS. I would have expected that it would only try TMPDIR on Unix-like
by dalke 12y ago
What's a bit unusual about Python is that it tries all three environment variables on every OS. I would have expected that it would only try TMPDIR on Unix-like machines, and TMP/TEMP on Windows-based machines. There's no compatibility expectation that Windows environment variables would work on Unix-like OSes, or vice versa.
FWIW, TMPDIR was part of standard Unix practices before Torvalds wrote the first line of the Linux kernel. For example, 4.3BSD-Reno came out 1990 . If you grab the tape from http://sourceforge.net/projects/bsd42/files/Install%20tapes/4.3%20BSD%20RENO/ http://sourceforge.net/projects/bsd42/files/Install%20tapes/... and page through it you'll see the man pages were "Printed 7/27/90" and contain things like:
If the environment variable TMPDIR is set, the string
denoted by TMPDIR will be used as the name of the directory
where the temporary files are created.
-- yacc(1)
The environmental variable ``TMPDIR'' (if set), the argument
dir (if non-NULL), the directory ``/usr/tmp'' and the direc-
tory ``/tmp'' are tried, in the listed order, as directories
in which to store the temporary file.
-- TMPFILE(3)
Python comes out of the Unix heritage (van Rossum contributed the glob() routine to BSD Unix in 1986), which is likely why the first commit of tempfile.py, Nov. 12 1991, mentions TMPDIR, though it didn't actually support the environment variable until Jan 14 1992.
OTOH, it didn't gain TMP/TEMP support until Aug 12 1997. Even then, the file says at the top:
# XXX This tries to be not UNIX specific, but I don't know beans about
# how to choose a temp directory or filename on MS-DOS or other
# systems so it may have to be changed...