1 00:00:00,690 --> 00:00:02,290 - [Instructor] For this self-check exercise, 2 00:00:02,290 --> 00:00:04,930 we'd like you to read in the contents 3 00:00:04,930 --> 00:00:08,450 of the grades.txt file that you created 4 00:00:08,450 --> 00:00:11,440 in the previous self-check exercise. 5 00:00:11,440 --> 00:00:14,610 So, go ahead and read that in and display the information 6 00:00:14,610 --> 00:00:19,350 in columns that have the heads ID, Name, and Grade. 7 00:00:19,350 --> 00:00:21,220 Pause the video to give that a shot. 8 00:00:21,220 --> 00:00:23,123 Then, come back to see the answer. 9 00:00:27,300 --> 00:00:29,210 Okay, let's reveal our answer. 10 00:00:29,210 --> 00:00:31,110 And, as you can see once again, 11 00:00:31,110 --> 00:00:33,440 we're creating a with statement here 12 00:00:33,440 --> 00:00:35,950 in which we're going to open the grades.txt file 13 00:00:37,344 --> 00:00:39,450 and we're assuming it's in the same folder 14 00:00:39,450 --> 00:00:41,840 from which we're executing at the moment. 15 00:00:41,840 --> 00:00:44,720 We're going to open that file for reading this time. 16 00:00:44,720 --> 00:00:47,270 So, we want to get data out of the file. 17 00:00:47,270 --> 00:00:50,240 And, we're going to call that file object grades 18 00:00:50,240 --> 00:00:53,110 for use inside the with statement. 19 00:00:53,110 --> 00:00:55,940 Next, we display our three column heads 20 00:00:55,940 --> 00:00:58,057 and, in this case, we've formatted the string 21 00:00:58,057 --> 00:01:01,410 "ID" left-aligned in a field of four, 22 00:01:01,410 --> 00:01:04,380 the string "Name," left-aligned in a field of seven, 23 00:01:04,380 --> 00:01:08,460 and for the "Grade" we're simply displaying the word grade 24 00:01:08,460 --> 00:01:10,760 in the last position here. 25 00:01:10,760 --> 00:01:13,380 Then, we have a for loop that's going to iterate one line 26 00:01:13,380 --> 00:01:16,070 at at a time through the grades file object. 27 00:01:16,070 --> 00:01:18,200 And, for each of those values, we're going 28 00:01:18,200 --> 00:01:21,700 to split the string into a list of tokens, 29 00:01:21,700 --> 00:01:24,300 a list of strings, and, within each of our records, 30 00:01:24,300 --> 00:01:26,430 we had written out the stuff previously 31 00:01:26,430 --> 00:01:29,430 as a student ID, a name, and a grade. 32 00:01:29,430 --> 00:01:31,830 So, we're creating variables into which 33 00:01:31,830 --> 00:01:35,520 we'll unpack each split record of information. 34 00:01:35,520 --> 00:01:39,160 And then, we go ahead and format a line of text, 35 00:01:39,160 --> 00:01:42,430 including the string "ID" left-aligned in field of four. 36 00:01:42,430 --> 00:01:44,570 Then, "Name" left-aligned in a field of seven, 37 00:01:44,570 --> 00:01:47,630 so those will align under the ID and Name columns. 38 00:01:47,630 --> 00:01:49,720 And then, finally we display the grade 39 00:01:49,720 --> 00:01:52,340 which will appear under the grade heading. 40 00:01:52,340 --> 00:01:54,163 So, let's go ahead and execute that. 41 00:01:56,190 --> 00:02:00,140 And, as you can see, we do indeed get the three records 42 00:02:00,140 --> 00:02:02,030 of information that we had shown you 43 00:02:02,030 --> 00:02:04,673 in the previous self-check exercise.