From the course: Complete Guide to Python for Data Engineering: From Beginner to Advanced

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: File handling

Solution: File handling

`(upbeat music) - [Instructor] Let's understand the problem statement. The problem statement says, first, we have a string which we want to write in a file. Then we have to read the same file, and then we need to ensure that whatever we have written in the file, are we getting the exact same string or not? Now, for this purpose, we are going to use our knowledge of file input output that we have learned during this module. So how you can write the file, the function is with open, and let's have our file name as example.TX3. Now I want to write the file. So I will open it in the mode that is W. W and I will say S file. Now what I can do is I have to say file.write so that I can write the text inside it and the string which I want to write inside it, is available to me as an input parameter here that is text. So I will just pass the text here. This will going to write the input text into a file called example.txt.…

Contents