From the course: Python: Working with Files
Unlock this course with a free trial
Join today to access over 25,400 courses taught by industry experts.
Work with temporary files in Python - Python Tutorial
From the course: Python: Working with Files
Work with temporary files in Python
- [Instructor] Temporary files can come in handy as a quick backup or storage for an intermediate state. We can create temporary files in Python using the temp file module. Temporary files can come in handy as a quick backup or storage for an intermediate state. We can create temporary files in Python using the temp file module. The temp file module automatically deletes the temporary file once the file is closed. Let's take a look at how it works. To start, we'll import the temp file module. To create a temporary file, we can open a temporary file object. We'll open it in write and read mode, w plus. This looks a little different than the previous pattern because we don't give the file a name. Since the file is temporary and it will be deleted after the file is closed, there's no need to provide a name. Let's write out some content to our temp file. tf.write. In order to read the file, we'll need to go back to the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.