
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to create a unique temporary file name using Python?
You can use the tempfile module to create a unique temporary file in the most secure manner possible. There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Note that the user of mkstemp() is responsible for deleting the temporary file when done with it. To create a new temporary file, use it as follows −
import tempfile _, temp_file_path = tempfile.mkstemp() print("File path: " + temp_file_path)
Note that you need to manually delete this file after you're done with it.
- Related Articles
- How to generate secure temporary file name using Python?
- How to create a temporary file using PowerShell?
- How to create a unique directory name using Python?
- Golang program to create a temporary file
- Create a temporary file in Java
- How to create a tar file using Python?
- How to create a zip file using Python?
- How to create hardlink of a file using Python?
- How to create softlink of a file using Python?
- Program to make file names unique using Python
- How to create a duplicate file of an existing file using Python?
- How to create an empty file using Python?
- How to delete a temporary file in Java?
- Create a GUI to convert CSV file to Excel file using Python
- Create temporary file in specified directory in Java

Advertisements