-2

I've got my code, I'm trying to make a mood diary of some sorts, it works fine, but when I go back to the script and run it again to add another entry, it just overrides my last entry, how could i prevent this?

import datetime

date = datetime.datetime.now()
print('My Mood Diary:')
mood = input('How are you feeling today? ')
text_file = open("Diary.txt", "w")
text_file.write('Date:\n')
text_file.write(date.strftime("%Y-%m-%d @ %H:%M:%S\nEntry:\n"))
text_file.write(mood)
text_file.write('\n')
text_file.close()
possum
  • 1,837
  • 3
  • 9
  • 18

1 Answers1

0

Use append:

text_file = open("Diary.txt", "a")
                               ^
Jonas
  • 1,749
  • 1
  • 10
  • 18