Felix Andrea
Profilo di
Nome | Felix Andrea |
---|---|
Indirizzo email | felixandreaim@gmail.com |
Avatar | |
Messaggi | 1 |
Firma forum | |
-
- 2024-11-02 10:03:49
- Re: Issues with File Handling in Python
- Forum >> Programmazione Python >> Files e Directory
- When you open a file with the "w" mode, it deletes the existing content and writes new data, so your behavior is expected. If you want to add content without overwriting the old data, you should use the "a" (append) mode. Here’s how to modify your code:
# Appending to a file
with open('data.txt', 'a') as file:
file.write('New content\n')
Good luck!