Book Image

Modern Python Standard Library Cookbook

By : Alessandro Molina
Book Image

Modern Python Standard Library Cookbook

By: Alessandro Molina

Overview of this book

The Python 3 Standard Library is a vast array of modules that you can use for developing various kinds of applications. It contains an exhaustive list of libraries, and this book will help you choose the best one to address specific programming problems in Python. The Modern Python Standard Library Cookbook begins with recipes on containers and data structures and guides you in performing effective text management in Python. You will find Python recipes for command-line operations, networking, filesystems and directories, and concurrent execution. You will learn about Python security essentials in Python and get to grips with various development tools for debugging, benchmarking, inspection, error reporting, and tracing. The book includes recipes to help you create graphical user interfaces for your application. You will learn to work with multimedia components and perform mathematical operations on date and time. The recipes will also show you how to deploy different searching and sorting algorithms on your data. By the end of the book, you will have acquired the skills needed to write clean code in Python and develop applications that meet your needs.
Table of Contents (21 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Named temporary files


Usually when working with temporary files, we don't care where they are stored. We need to create them, store some content there, and get rid of them when we are done. Most of the time, we use temporary files when we want to store something that is too big to fit in memory, but sometimes you need to be able to provide a file to another tool or software, and a temporary file is a great way to avoid the need to know where to store such a file.

In that situation, we need to know the path that leads to the temporary file so that we can provide it to the other tool.

That's where tempfile.NamedTemporaryFile can help. Like all other tempfile forms of temporary files, it will be created for us and will be deleted automatically as soon as we are done working with it, but different from the other types of temporary files, it will have a known path that we can provide to other programs who will be able to read and write from that file.

How to do it...

tempfile.NamedTemporaryFile will...