Chapter 1

Working with External Files

IN THIS CHAPTER

check Working with text and binary files

check Opening, closing, and reading the contents of a file

check Looping through a file

check Reading and copying a binary file

check Working with CSV files

check Importing CSV to objects and dictionaries

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 ...

Get Python All-in-One For Dummies, 2nd Edition 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.