read mode, write mode vs. read method and write method | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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 Antwort
+ 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
ΛM!N - avatar