1
00:00:01,150 --> 00:00:06,580
A better way to do this so create the file, read the content, and close the file is to use the

2
00:00:06,580 --> 00:00:08,250
with context manager.

3
00:00:08,380 --> 00:00:16,110
The way you do that is again use the open function which works with the same, fruits.txt.

4
00:00:16,450 --> 00:00:24,860
Now you say s might file, my file is just a variable and then you have to indent.

5
00:00:24,970 --> 00:00:33,970
So what you have done here is you have created this my file equal to open fruits.txt, exactly

6
00:00:33,970 --> 00:00:35,550
the same.

7
00:00:35,600 --> 00:00:42,370
The difference here is that you write everything that has to do with processing that file object

8
00:00:42,370 --> 00:00:49,870
you'll have to write everything under this line, indented under that line as a block, that will make

9
00:00:49,870 --> 00:00:52,090
things more organized.

10
00:00:52,090 --> 00:00:57,370
So in this case what we want to do to the file is to read it like that.

11
00:00:57,370 --> 00:01:04,930
Once you are done then you just close the indentation so that next lines will be on indented like the

12
00:01:04,930 --> 00:01:10,490
print line, see what's going to happen here.

13
00:01:10,600 --> 00:01:16,720
So that is the expected output of the print content.

14
00:01:16,930 --> 00:01:21,700
Even if you delete this, not to confuse you again you get the same output.

15
00:01:21,760 --> 00:01:30,040
So this output is actually of this line, and closing the file is not necessary here because the with

16
00:01:30,040 --> 00:01:33,870
context manager will apply the close method implicitly.

17
00:01:33,880 --> 00:01:38,220
So your file will be closed once these block ends.

18
00:01:38,260 --> 00:01:42,390
So please use the with context manager and this is how you do it.

