liveBook · Manning

Chapter 20: Basic file wrangling

What you will learn in chapter 20 of The Quick Python Book, Fourth Edition

The introduction frames file wrangling as the planned, automated management of growing collections of files that cannot be discarded immediately.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction frames file wrangling as the planned, automated management of growing collections of files that cannot be discarded immediately.

Key terms: log files, regular data feed, manual intervention

20.1 The problem: The never-ending flow of data files

This section explains why a continuing flow of valuable data files becomes a file-management and storage problem.

Key terms: data files, flat text files, raw data, storage

20.2 Scenario: The product feed from hell

The section uses a daily product-feed example to show why files need archiving and how pathlib can date, rename, and move them.

Key terms: product feed, raw data, archive folder, pathlib, glob, Path objects, stem, suffix, rename

20.3 More organization

This section replaces a flat, date-renamed file archive with date-named subdirectories that keep each received set together.

Key terms: archive, subdirectory, date received, set of files, date string, archive directory, filename

20.4 Saving storage space: Compression and grooming

The section explains why accumulating data files create a storage problem that adding disk space only postpones.

Key terms: data files, storage, cloud-based platform

20.4.1 Compressing files

This section replaces daily archive subdirectories with date-named zip files to save storage space.

Key terms: compression, zip file, date string, zipfile library, zipfile object, unlink

20.4.2 Grooming files

This section explains when to remove older archived data files and how to use Python to retain selected files by date.

Key terms: grooming, archived copy, grooming script, archiving script, datetime, pathlib, glob, stem, strptime, timedelta

20.5 Summary

Concepts explained in this chapter

← Chapter 19: Using Python libraries Chapter 21: Processing data files →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.