(original) (raw)
On Tue, Mar 19, 2019 at 6:27 AM Antoine Pitrou <solipsis@pitrou.net> wrote:
\-1\. Please don't remove tempfile.mktemp(). mktemp() is useful to
create a temporary \*name\*. All other tempfile functions create an
actual file and impose additional burden, for example by making the
file unaccessible by other processes. But sometimes all I want is a
temporary name that an \*other\* program will create / act on, not Python.
It's a very common use case when writing scripts.
The only reasonable workaround I can think of is to first create a
temporary directory using mkdtemp(), then use a well-known name inside
that directory. But that has the same security implications AFAICT,
since another process can come and create the file / symlink first.
If all you need is a random name, why not just use a random number generator?
E.g. I see code like this:
binascii.hexlify(os.urandom(8)).decode('ascii')
--Guido van Rossum (python.org/\~guido)