In this video, you will learn how to read the contents of a text files via Python.
Again, we use the with methods and again we use that open methods.
And again, we supply the path to the file we want to reads.
So this should be an existing file.
Otherwise, you will get an error.
Now, previously we use W, which meant we opened the file for writing the song We use all.
S file, so file is a variable that has.
The final object created by this function and then filed dozens of reads reads, is the methods, but
what do we want to do with this train?
Because this outputs a string.
The string is the contents of the text file.
What you want to do with that depends on your project purpose.
Do you want to merge the text of multiple text files?
Then you will use to each text in a variable or, you know, list and then you merge the list?
We're going to do that.
And but for this purpose, let's just talk this to a content variable.
And then once you're done with that, you can exit the block.
So you can indent and then maybe print content to see what we get.
Run.
And this is the output, so that is the text.
So that is the contents of the text file here.
Now, in some places, you will see that this or mode is not included and you've got to run this code
and you get the same articles.
That is because by default, the modes of this function is set to order.
So you can just admit that argument and it will work the same.
But I do recommend it to include the arguments because it makes the codes more more readable, more
explicit.
You know that you have opened the file for reading.
So it improves readability of the codes.
So that is how to read the contents of the file.
Previously, we worked on writing the contents inside the file.
This was a body reading.
Now we are ready to do all kinds of file manipulations using the open function.
So you'll practice this in the following videos.
See you in the next one.