1
00:00:00,090 --> 00:00:05,760
In this video, you will learn how to read the contents of a text files via Python.

2
00:00:06,060 --> 00:00:10,350
Again, we use the with methods and again we use that open methods.

3
00:00:11,100 --> 00:00:15,300
And again, we supply the path to the file we want to reads.

4
00:00:15,480 --> 00:00:18,720
So this should be an existing file.

5
00:00:19,050 --> 00:00:20,970
Otherwise, you will get an error.

6
00:00:21,570 --> 00:00:28,560
Now, previously we use W, which meant we opened the file for writing the song We use all.

7
00:00:31,010 --> 00:00:35,000
S file, so file is a variable that has.

8
00:00:36,730 --> 00:00:44,440
The final object created by this function and then filed dozens of reads reads, is the methods, but

9
00:00:44,440 --> 00:00:46,390
what do we want to do with this train?

10
00:00:46,390 --> 00:00:49,090
Because this outputs a string.

11
00:00:49,330 --> 00:00:52,870
The string is the contents of the text file.

12
00:00:54,330 --> 00:00:58,770
What you want to do with that depends on your project purpose.

13
00:00:59,790 --> 00:01:03,450
Do you want to merge the text of multiple text files?

14
00:01:03,780 --> 00:01:10,320
Then you will use to each text in a variable or, you know, list and then you merge the list?

15
00:01:10,530 --> 00:01:11,550
We're going to do that.

16
00:01:12,190 --> 00:01:16,650
And but for this purpose, let's just talk this to a content variable.

17
00:01:17,730 --> 00:01:21,500
And then once you're done with that, you can exit the block.

18
00:01:21,720 --> 00:01:27,090
So you can indent and then maybe print content to see what we get.

19
00:01:28,080 --> 00:01:28,440
Run.

20
00:01:29,900 --> 00:01:32,540
And this is the output, so that is the text.

21
00:01:35,290 --> 00:01:38,440
So that is the contents of the text file here.

22
00:01:39,290 --> 00:01:47,140
Now, in some places, you will see that this or mode is not included and you've got to run this code

23
00:01:47,140 --> 00:01:48,790
and you get the same articles.

24
00:01:49,090 --> 00:01:55,030
That is because by default, the modes of this function is set to order.

25
00:01:55,840 --> 00:02:00,620
So you can just admit that argument and it will work the same.

26
00:02:00,640 --> 00:02:08,620
But I do recommend it to include the arguments because it makes the codes more more readable, more

27
00:02:08,620 --> 00:02:09,340
explicit.

28
00:02:09,550 --> 00:02:12,970
You know that you have opened the file for reading.

29
00:02:13,940 --> 00:02:17,220
So it improves readability of the codes.

30
00:02:17,870 --> 00:02:21,380
So that is how to read the contents of the file.

31
00:02:22,070 --> 00:02:25,220
Previously, we worked on writing the contents inside the file.

32
00:02:25,290 --> 00:02:26,520
This was a body reading.

33
00:02:26,540 --> 00:02:34,340
Now we are ready to do all kinds of file manipulations using the open function.

34
00:02:35,240 --> 00:02:37,790
So you'll practice this in the following videos.

35
00:02:37,940 --> 00:02:38,990
See you in the next one.

