Files and Exceptions
We will learn more about working with files and also try
to better understand exceptions.( you will see that try
is sort of a pun because it is one of Python's reserved keywords related to exception errors.)
It is common to raise exceptions when working with files so "files and exceptions" are often covered in tandem.
- Look at this info on file handling: File Handling
- Scan over this list of exceptions and the Try, Except, Else, Finally, and Raise blocks.
Here are two videos you can watch before class if you have time:
Python in Easy Steps
I want to introduce a new free resource for you, Python in Easy Steps. This is an affordable book priced $15.99. You can access it for free through the UNC University Libraries website: https://ebookcentral.proquest.com/lib/unc/detail.action?docID=7075484
We will use this book to look at File Handling and Exceptions—it is only a few pages and the concepts are boiled down to the absolute need-to-know level.
You will want to download Chapter 4, Defining Functions, and Chapter 6, Managing Strings.
Be sure to download them to your computer.
I renamed my files pies-functions.pdf
and pies-strings.pdf
, so you may want to do the same to follow along with me.
When you open each file you will see a table of contents. Click Reading and writing files in the Managing Strings Chapter, and click Handling exceptions in the Defining Functions Chapter.
Before we get started, take a look at this list that I compiled from searching for free Python books at UNC libraries. I sorted the list in this manner: Sort by Relevance
, Year (new to old)
, so none of these resources are from before 2023. It is important to use recent publications when learning a Programming Language as things change fast.
New REPL in Python 3.13
I just discovered that the REPL in Python 2.13 has a major upgrade. So that is affecting this class because we all installed Python 2.12.