1
00:00:00,810 --> 00:00:09,810
When you create a file object, a file object is created in RAM and it's going to remain there until the

2
00:00:09,810 --> 00:00:12,480
execution of your program ends.

3
00:00:12,480 --> 00:00:18,420
Therefore it might be a good idea to actually close the file and so that the file is deleted from the

4
00:00:18,420 --> 00:00:18,840
memory.

5
00:00:18,840 --> 00:00:26,010
Once you are done processing that file for example in this script you are creating the file object.

6
00:00:26,010 --> 00:00:31,180
And here you are reading the contents of that file object and storing it as a string.

7
00:00:31,440 --> 00:00:39,300
So my file.reads outputs a string which represents the the text of the file, that string will be

8
00:00:39,300 --> 00:00:41,530
stored in this contents variable.

9
00:00:41,550 --> 00:00:43,830
So here I am done with processing the file.

10
00:00:43,830 --> 00:00:44,610
Then I can...

11
00:00:44,610 --> 00:00:49,230
After that I'm just processing the string that I saved in this variable.

12
00:00:49,260 --> 00:00:58,740
Therefore it makes sense to apply my file.close even though this is not strictly mandatory but it's

13
00:00:58,740 --> 00:01:00,090
a good idea to use it.

14
00:01:00,120 --> 00:01:05,110
So if you do that you'll still get the correct outputs.

15
00:01:05,370 --> 00:01:11,430
Something you should know now is that if you apply my file.read again after you have closed

16
00:01:11,430 --> 00:01:12,180
the file,

17
00:01:12,180 --> 00:01:14,270
you're going to get an error.

18
00:01:14,370 --> 00:01:22,230
It says that this operation is being performed on a closed file so you cannot do that.

19
00:01:22,320 --> 00:01:25,930
So this is how to create a file and close it.

20
00:01:25,980 --> 00:01:29,260
There is a better way to do all that.

21
00:01:29,620 --> 00:01:30,960
I'll show you that in the next video.

