Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

Chapter 14: Files

close up of a computer screen with a file menu open
Figure 14.1 credit: Larissa Chu, CC BY 4.0

Programming often involves reading information from files and writing information into files. This chapter begins by introducing how to read from and write into files in Python.

Reading and writing files can lead to exceptions when the file specified cannot be found. There are many other situations in which exceptions can occur. The second half of the chapter introduces exceptions and how to handle exceptions in Python.

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or any other accessibility standard. Every page is built against an automated accessibility gate, and our target for the published editions is WCAG 2.2 Level AA. If something is unusable, please tell us.