0
What is reading file
I don't understand file = open("filename.txt", "r") cont = file.read() print(cont) file.close() Who understand can ask me please...
1 Respuesta
+ 8
The first line would allow you to access and read (because of the "r") the file with name "filename.txt" on the console.
"file.read()" would then print the file in a readable format to the console and then that is saved to cont so when you print cont it would do that.
"file.close()" would close the access to the file from the console so to access it again you would have repeat something simpler to the first step.
For more information you can go to the "Exceptions & Files" section on Sololearn's Python tutorial (specifically the 'Opening Files', 'Reading Files', 'Writing Files' and 'Working with Files' parts) or you can read these two parts from the official Python documentation:
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects