"That name can be retrieved from the name member of the file object."

means that you can get the name of the temporary file created like so:

In [4]: import tempfile

In [5]: tf = tempfile.NamedTemporaryFile()  
In [6]: tf.name  # retrieve the name of the temp file just created
Out[6]: 'c:\\blabla\\locals~1\\temp\\tmptecp3i'

Note: By default the file will be deleted when it is closed. However, if the delete parameter is False, the file is not automatically deleted. See the Python docs on this for more information.

Since you can retrieve the name of each of the 50 temp files you want to create, you can save them, e.g., in a list, before you use them again later (as you say). Just be sure to set the delete value accordingly so that the files don't disappear when you close them (in case you plan to close, and then later reopen them).

I explained how to create temporary filenames in more detail here Best way to generate random file names in Python

Answer from Levon on Stack Overflow
🌐
Python
docs.python.org › 3 › library › tempfile.html
tempfile — Generate temporary files and directories
Source code: Lib/tempfile.py This module creates temporary files and directories. It works on all supported platforms. TemporaryFile, NamedTemporaryFile, TemporaryDirectory, and SpooledTemporaryFil...
🌐
Python Module of the Week
pymotw.com › 2 › tempfile
tempfile – Create temporary filesystem resources. - Python Module of the Week
The tempfile module provides several functions for creating filesystem resources securely. TemporaryFile() opens and returns an un-named file, NamedTemporaryFile() opens and returns a named file, and mkdtemp() creates a temporary directory and returns its name.
🌐
Medium
siddharth1.medium.com › temp-files-and-tempfile-module-in-python-with-examples-570b4ee96a38
temp files and tempfile module in python(with examples) | by Siddharth Kshirsagar | Medium
August 6, 2020 - import os import pathlib import tempfilewith tempfile.NamedTemporaryFile() as tmp: print(tmp) print(temp.name) f = pathlib.Path(temp.name) # the temp file does not exist after closing it.
🌐
Safjan
safjan.com › home › note › mastering temporary files and directories with...
Mastering Temporary Files and Directories with Python's tempfile Module
July 12, 2023 - import tempfile import os with tempfile.TemporaryDirectory() as temp_dir: print(f'Temporary directory: {temp_dir}') temp_file_path = os.path.join(temp_dir, 'temp_file.txt') with open(temp_file_path, 'w') as temp_file: temp_file.write('This file is inside the temporary directory.') print('Temporary directory and file have been deleted.') You can customize the names of temporary files and directories using the prefix, suffix, and dir arguments. For example: import tempfile with tempfile.NamedTemporaryFile(prefix='my_temp_', suffix='.txt', dir='/tmp') as temp_file: print(f'Temporary file path: {temp_file.name}')
🌐
Heitor's Log
heitorpb.github.io › bla › pytmp
Temporary files and directories in Python | Heitor's log
One interesting thing about this tempfile.TemporaryFile object is that it is kind of a ghost on Unixes: the file exists, but has no readable path, only a file descriptor. The documentation says (as of Python 3.13): Under Unix, the directory entry for the file is either not created at all or is removed immediately after the file is created. Pretty weird, in my opinion, but also cool. If you need a file with a name, use tempfile.NamedTemporaryFile() instead.
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 14423
tempfile.NamedTemporaryFile can not create temp file : Forums : PythonAnywhere
d.save(formats=['png'], outDir=foldername, fnRoot=filename) the 'foldername' is absolute path ... with tempfile.NamedTemporaryFile(dir='media', suffix=".png", delete=True) as tmpfile: nanu = tmpfile.name foldername, filename = os.path.split(nanu)
Find elsewhere
🌐
Echorand
echorand.me › posts › named_temporary_file
tempfile.NamedTemporaryFile() in Python - Exploring Software
January 20, 2016 - # Remove the file os.unlink(or...(original_path) Case #3: You need a temporary file, write some contents, read from it later · This use case is where you need a temporary file, but you want to work with it like a "normal" file on disk - write something to it and later, read it from it. In other words, you just want to control when the file gets removed from disk. from tempfile import NamedTemporaryFile # When ...
🌐
Geek Python
geekpython.in › tempfile-in-python
How To Use tempfile To Create Temporary Files and Directories in Python
August 15, 2023 - We got the location of the object in memory when we printed the object temp_file, and we got the random name tmp5jyjavv2 with the entire path when we printed the name of the temporary file.
🌐
Google Groups
groups.google.com › g › dev-python › c › 1-cmCnOve08
[Python-Dev] NamedTemporaryFile and context managers
@contextmanager def NamedTemporaryFile(): with TemporaryDirectory() as td: filename = os.path.join(td, 'tempfile') with open(filename, 'wb') as fp: yield fp ·
🌐
TakoVibe
takovibe.com › home › blog › python tempfile explained: temporary files, auto-deletion & common mistakes
Python tempfile Explained: Temporary Files, Auto-Deletion & Common Mistakes | Rahul Beniwal | TakoVibe
August 21, 2025 - NamedTemporaryFile → temporary files with paths · TemporaryDirectory → disposable directories · Custom prefixes, suffixes, and locations · 👉 Next time you need temp storage for uploads, downloads, or caching, you’ll know exactly how to use Python’s tempfile like a pro ·
🌐
Modular
docs.modular.com › apis
NamedTemporaryFile | Modular
from tempfile import NamedTemporaryFile from pathlib import Path def main(): var p: Path with NamedTemporaryFile(mode="rw") as f: p = f.name f.write("Hello world!") f.seek(0) print( f.read() == "Hello world!" ) print(String(p), p.exists()) #Removed by default ·
🌐
Adam Johnson
adamj.eu › tech › 2024 › 12 › 30 › python-temporary-files-directories-unittest
Python: create temporary files and directories in unittest - Adam Johnson
December 30, 2024 - NamedTemporaryFile has been swapped for TemporaryDirectory. It creates a directory and completely removes it in its exit method. temp_dir is not an object but a string containing the path of the temporary directory.
🌐
Python Pool
pythonpool.com › home › blog › understanding the python tempfile module
Understanding the Python Tempfile Module - Python Pool
July 9, 2021 - Here we have to create a named temporary file. The only difference, which is quite evident, is that instead of, Temporary file, we have used NamedTemporaryfile. A random file name is allotted, but it is clearly visible, unlike the previous case. Another thing that can be verified here is the structure profile/AppData/Local/Temp(as mentioned for windows os).
🌐
Linux Hint
linuxhint.com › tempfile_python
Working with tempfile in python – Linux Hint
# Import tempfile module import tempfile # Import os module import os # Declare object to create a temporary file with suffix and prefix tmp = tempfile.NamedTemporaryFile(mode='w+t', prefix='tm_', suffix='_fl', dir='/tmp') # Print the temporary filename print(tmp.name) try: # Print message before writing print('Write data to temporary file...') # Write data to a temporary file tmp.write('This is a temporary content.') finally: # Remove the file automatically tmp.close() if(os.path.exists(tmp.name) == False): print('File is removed')
🌐
Python.org
discuss.python.org › ideas
tempfile.TemporaryDirectory().name should return pathlib.Path instead of str
December 11, 2023 - if not that then maybe another property instead? Something like >>> tempfile.TemporaryDirectory().name 'C:\\Users\\monarch\\AppData\\Local\\Temp\\tmp57z91nmz' >>> tempfile.TemporaryDirectory().path WindowsPath('C:/Users…
🌐
Stack Abuse
stackabuse.com › the-python-tempfile-module
The Python tempfile Module
July 20, 2023 - In our previous example, we have seen that the temporary file created using the TemporaryFile() function is actually a file-like object without an actual file name. Python also provides a different method, NamedTemporaryFile(), to create a file with a visible name in the file system.
🌐
GeeksforGeeks
geeksforgeeks.org › python-tempfile-module
Python tempfile module - GeeksforGeeks
December 11, 2020 - If your application spans multiple processes, or even hosts, naming the file is the simplest way to pass it between parts of the application. The NamedTemporaryFile() function creates a file with a name, accessed from the name attribute.