Chapter 1

Working with External Files

IN THIS CHAPTER

Bullet Working with text and binary files

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

Bullet Looping through a file

Bullet Reading and copying a binary file

Bullet Working with CSV files

Bullet 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, 3rd 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.