Topic - Reading Data from Files
Topics:
- Types of Files that are easy to use in Python
- Opening a file for reading
- fin = open("filename","r", [encoding="utf-8"] )
- Commands to read from files:
- oneline = fin.readline() [What we will use most]
- alllines = fin.read()
- allLinesSplitUp = fin.readlines()
Materials:
- Files I will use in this lesson. To download these files you should right-click and "save as"
- This lesson consists of five videos totalling 70 minutes.
Motivating Using Files in Python
For the rest of this course we will be working with data that comes out of files. In this first video I explain a little bit about why this is really helpful and show you the types of files that we can work with.
VIDEO - File I/O Motivation (17 minutes)
Using Python to read from a file one line at a time
Now that we have our file of data and understand what it looks like, let's learn how to read the data one line at a time.
VIDEO - open(), close(), readline() (16 minutes)
VIDEO - readlines() and read() (7 minutes)
VIDEO - using the loop iterator to read [variation on readline() and what we will most use] (14 minutes)
Processing this data to get us interesting results
VIDEO - split() and converting the data to set it up for my BMI (16 minutes)