Let’s say that you need to open, read, and write text files in Python. First you can use the
open() built-in function to open the file. Once the file is opened you can use the two built-in methods
write() to read from the file and to write to the file.
>>> opened_file = open('file.txt')
>>> the_file_content = opened_file.read()
'Hi there! I am a .txt file!'