- [Instructor] For this self-check exercise,
we'd like you to read in the contents
of the grades.txt file that you created
in the previous self-check exercise.
So, go ahead and read that in and display the information
in columns that have the heads ID, Name, and Grade.
Pause the video to give that a shot.
Then, come back to see the answer.
Okay, let's reveal our answer.
And, as you can see once again,
we're creating a with statement here
in which we're going to open the grades.txt file
and we're assuming it's in the same folder
from which we're executing at the moment.
We're going to open that file for reading this time.
So, we want to get data out of the file.
And, we're going to call that file object grades
for use inside the with statement.
Next, we display our three column heads
and, in this case, we've formatted the string
"ID" left-aligned in a field of four,
the string "Name," left-aligned in a field of seven,
and for the "Grade" we're simply displaying the word grade
in the last position here.
Then, we have a for loop that's going to iterate one line
at at a time through the grades file object.
And, for each of those values, we're going
to split the string into a list of tokens,
a list of strings, and, within each of our records,
we had written out the stuff previously
as a student ID, a name, and a grade.
So, we're creating variables into which
we'll unpack each split record of information.
And then, we go ahead and format a line of text,
including the string "ID" left-aligned in field of four.
Then, "Name" left-aligned in a field of seven,
so those will align under the ID and Name columns.
And then, finally we display the grade
which will appear under the grade heading.
So, let's go ahead and execute that.
And, as you can see, we do indeed get the three records
of information that we had shown you
in the previous self-check exercise.