Skip to ContentGo to accessibility pageKeyboard shortcuts menu
OpenStax Logo

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.

Citation/Attribution

This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's permission.

Want to cite, share, or modify this book? This book uses the Creative Commons Attribution License and you must attribute OpenStax.

Attribution information
  • If you are redistributing all or part of this book in a print format, then you must include on every physical page the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
  • If you are redistributing all or part of this book in a digital format, then you must include on every digital page view the following attribution:
    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction
Citation information

© Feb 26, 2024 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution License . The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.