views:

35

answers:

1
>>> import tempfile
>>> tempfile.mkstemp()
(3, 'c:\\docume~1\\k0811260\\locals~1\\temp\\tmpk6tpd3')

It works, but looks a bit strange. and the actual temporary file name is more than 8 letters.

Why doesn't it use long file names instead?

+3  A: 

mkstemp uses the environment variables TMPDIR, TEMP or TMP (the first one that is set) to determine where to put your temporary file. One of these is probably set to c:\docume~1\k0811260\locals~1\temp on your system. Issue

echo %%tmp%%

etc. in a command window ("DOS box") to find out for sure.

Which, in fact, is a good thing because some naïve modules/programs (e.g., those that call external OS commands) may get confused when a directory name contains a space, due to quoting issues.

larsmans
It's rather a bad thing because 8.3 names can be deactivated, and then `tempfile` would fail.
Philipp
I'd assume that whatever is setting the environment variable would have set it to something else in that case.
Kylotan
@Philipp: then any program that uses the current setting of TMP will fail, so that variable will have to be reset. `tempfile` will try its other options, which includes `C:\temp` and some other common dirs. A safe program should use its `dir` argument.
larsmans
Running a Windows system without 8.3 name support is nonstandard, and if you do that you won't be surprised when some things don't work right.
kindall