+ 3

read mode, write mode vs. read method and write method

So, do I understand them correctly as the following? file = open ("filename", "r") # opens the file in the read mode, but doesn't read the file yet. file.read() #The file is read file = open ("filename", "w") # immediately erases the contents that were already there. This is different from the "r". file.write("This is the new contents written to the file that was emptied when being opened in a write mode") # write new contents in So in general, "read mode" does nothing to the file while "write mode" immediately erases the contents of the file. Is this correct? Thank you for your help, friends!

29th Jun 2019, 8:59 PM
Yang Yang
Yang Yang - avatar
1 Answer
+ 3
Yes, you're right. Just to know you can use more arguments, too: https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_file_handling.asp
30th Jun 2019, 4:30 AM
ΛM!N - avatar