Skip to Content
Intuitive Python
book

Intuitive Python

by David Muller
May 2021
Intermediate to advanced
142 pages
3h 37m
English
Pragmatic Bookshelf
Content preview from Intuitive Python

Creating Temporary Workspaces with tempfile

The tempfile module allows you to create files and directories that are automatically deleted when you are done with them. As you’ll see in this section, the tempfile module can be particularly useful when testing code that writes to the file system by allowing you to create new and isolated files and directories that are automatically cleaned up for you as the test ends.

tempfile has a number of convenience functions and classes, but you’ll learn about two of the most useful in this section: NamedTemporaryFile and TemporaryDirectory.

Creating Temporary Files with NamedTemporaryFile

NamedTemporaryFile allows you to create a new file on the file system that is automatically deleted when you are done with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonic Programming

Pythonic Programming

Dmitry Zinoviev
Python for Geeks

Python for Geeks

Muhammad Asif

Publisher Resources

ISBN: 9781680508635Errata Page