1 00:00:00,000 --> 00:00:02,800 A better way to do this, so to create 2 00:00:02,835 --> 00:00:05,160 the file, or read the contents, and close 3 00:00:05,160 --> 00:00:07,350 the file is to use the with context 4 00:00:07,350 --> 00:00:09,990 manager. The way you do that is, again 5 00:00:09,990 --> 00:00:13,320 use the open function, which works the 6 00:00:13,320 --> 00:00:19,855 same, fruits.txt. Now, you say as myfile, 7 00:00:19,879 --> 00:00:22,110 myfile is just a variable, 8 00:00:22,470 --> 00:00:25,770 and then you have to indent. So what you 9 00:00:25,770 --> 00:00:28,920 have done here is you have created this, 10 00:00:29,046 --> 00:00:32,856 myfile equal to open fruits.txt, 11 00:00:33,330 --> 00:00:36,450 exactly the same. The difference here is 12 00:00:36,450 --> 00:00:39,060 that you will write everything that has 13 00:00:39,060 --> 00:00:42,090 to do with processing that file object, 14 00:00:42,270 --> 00:00:44,580 you will have to write everything under 15 00:00:44,580 --> 00:00:48,540 this line, indented under that line as a 16 00:00:48,540 --> 00:00:50,400 block, that's will make things more 17 00:00:50,705 --> 00:00:53,405 organized. So in this case, what we want 18 00:00:53,430 --> 00:00:55,830 to do to the file is to read it, like 19 00:00:55,830 --> 00:01:00,390 that. Once you are done, then you just 20 00:01:00,390 --> 00:01:02,580 close the indentation, so the next 21 00:01:02,580 --> 00:01:05,916 lines will be unindented, like the print line. 22 00:01:05,940 --> 00:01:08,057 [No audio] 23 00:01:08,089 --> 00:01:09,549 See what's going to happen here. 24 00:01:10,440 --> 00:01:14,790 So that is the expected output of the 25 00:01:14,790 --> 00:01:18,000 print content. Even if you delete this, 26 00:01:18,510 --> 00:01:20,760 not to confuse you, again you get the 27 00:01:20,760 --> 00:01:23,160 same output. So this output is actually 28 00:01:23,160 --> 00:01:24,366 of this line. 29 00:01:24,390 --> 00:01:26,390 [No audio] 30 00:01:26,415 --> 00:01:28,020 And closing the file is 31 00:01:28,020 --> 00:01:30,000 not necessary here because the with 32 00:01:30,000 --> 00:01:32,220 context manager will apply the close 33 00:01:32,220 --> 00:01:34,980 method implicitly. So your file will be 34 00:01:34,980 --> 00:01:38,820 closed once this block ends. So please 35 00:01:38,820 --> 00:01:40,842 use the with context manager 36 00:01:40,953 --> 00:01:42,086 and this is how you do it. 37 00:01:42,123 --> 00:01:45,499 [No audio]