tempfile
is a useful to create files and directories under system temp path whatever that is.
To create a temp directory, tempfile.TemporaryDirectory
returns a full path to temp directory.
In [8]: x = tempfile.TemporaryDirectory()
In [9]: x.name
Out[9]: '/tmp/tmp_olncqa8'
To create a file, tempfile.NamedTemporaryFile
does exactly that.
In [5]: x = tempfile.NamedTemporaryFile()
In [6]: x.name
Out[6]: '/tmp/tmpn7oud6l_'
PS. the directory path is determined with following rules
If dir is not None, the file will be created in that directory; otherwise, a default directory is used. The default directory is chosen from a platform-dependent list, but the user of the application can control the directory location by setting the TMPDIR, TEMP or TMP environment variables