Chapter 10
Working with External Files
IN THIS CHAPTER
Working with text and binary files
Opening, closing, and reading the contents of a file
Looping through a file
Reading and copying a binary file
Pretty much everything stored in your computer, be it a document, program, movie, photograph, and more, is stored in a file. Most files are organized into folders (also called directories). You can browse through folders and files by using Finder (on a Mac) or File Explorer or Windows Explorer (in Windows).
Python offers many tools for creating, reading from, and writing to many different kinds of files. In this chapter, you learn the most important skills for using Python code to work with files.
Understanding Text and Binary Files
There are basically two types of files:
- Text file: Contains plain text characters. When you open a text file in a text editor, it displays human-readable content. The text may not be in a language you know or understand, but you will see mostly normal characters that you can type at any keyboard.
- Binary file: Stores information in bytes that aren’t quite ...
Get Python Essentials For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.