0

The content of the file hAs been overwritten. How. Where. WhAt exActly

file = open("newfile.txt", "w") file.write("Some new text") file.close() file = open("newfile.txt", "r") print("Reading new contents") print(file.read()) print("Finished") file.close() PLEASE REFER TO PYTHON CORE>>>EXCEPTION>>>8.1WRITING FILES TOPIC IN PYTHON CORE

14th Feb 2021, 9:18 AM
We Doru
We Doru - avatar
1 Odpowiedź
+ 1
When you open a file in write mode: file = open("new_file.txt", 'w') ^ | That 'w' means write mode. It will overwrite whatever is in the opened file. If you want to add to existing text, use 'a' (append mode).
14th Feb 2021, 10:49 AM
Slick
Slick - avatar