Python: Working with Files
1h 41mIntermediate2021-07-21
Authors

Kathryn Hodge
Software Developer
Course details
When you’re working with files of any kind, nothing saves time like automation. No one wants to spend a day manually editing or renaming 1000 files. In this course, Kathryn Hodge shows you how to use Python to automate operating system tasks, aggregate data across multiple sources, save results to files, and level up your Python applications. Kathryn starts by introducing the idea of the file system with absolute versus relative paths, directory structures, and more. From there, she explores how to use tools from the Python Standard Library to retrieve metadata about the files and paths located on your machine. Once you know how to navigate to the appropriate files you want to work with, she shows how to process files with Python, parsing data not only in text formats, but also JSON and CSV. Finally, Kathryn looks at writing data to different file types and explains how to store that data within an archive well as with temporary files.
Skills covered
PythonProgramming LanguagesOpen SourceSoftware DevelopmentOne-Off
Concepts
Introduction
- Automate file tasks with Python
- Accessing Directory and File Details
Understand the file system
- Navigate the file system with os module
- Use os module to uncover path and file details
- Filter path names with glob module
- Recursively list all files in a directory
- Understand Python's new pathlib module
- Create directories in Python
- Challenge - Count files
- Solution - Count files
Processing Files
- Open files in Python
- Read text files in Python
- Parse JSON files with Python
- Read CSV files in Python with csv module and pandas
- Extract text from PDF files using Python
- Challenge - Aggregate data from multiple sources
Solution - Aggregate data from multiple sources
- Writing to Files
- Write data to a file in Python
- Move and rename files with Python
- Copy with Python
- Delete files with Python
- Save tabular data with csv module
- Write data to a JSON file in Python
- Challenge - Reorganize digital photo collection
Solution - Reorganize digital photo collection
- Working with Archives and Temporary Files
- Create ZIP archives with Python
- Read from and extract ZIP archives
- Open and read TAR archives
- Extract from and write to TAR archives
- Work with temporary files in Python
Conclusion
- Continue to analyze data with Python