Answers to Best way to generate random file names in Python show how to create temporary files in Python.
I only need to have a temporary file name in my case.
Calling tempfile.NamedTemporaryFile()
returns a file handle after actual file creation.
Is there a way to get a filename only? I tried this:
# Trying to get temp file path
tf = tempfile.NamedTemporaryFile()
temp_file_name = tf.name
tf.close()
# Here is my real purpose to get the temp_file_name
f = gzip.open(temp_file_name ,'wb')
...