-3

I am working on a school project and im trying to have the homework you right down saved to a txt file so it can call upon and read later. However, everytime it goes to write something new, it clears the previous text added.

the_journal_part = input("what subject would you like to take down homework for? ")

if the_journal_part == "exit" or the_journal_part == "Exit":
 print("leaving app") 
 time.sleep(5) 
 os.system("clear")
 exit()

homework = input("here's where you can take down your " + the_journal_part + " homework: ")
time.sleep(2)
os.system("clear")

f = open('homework.txt', 'r') 
f.read()
f = open('homework.txt', 'w')
f.write(the_journal_part + ': ' + homework )
f.close()

I have tried to make it write a null line before and after the text is written to give space but it still clears it. I've tried many things to make it work but nothing has worked. I have spent hours searching for an answer, its due in two weeks. Can anyone please help me?

martineau
  • 112,593
  • 23
  • 157
  • 280
Bonnie
  • 1
  • 1
  • 3
    What do you think opening a file with mode `"w"` means? – Scott Hunter May 06 '22 at 19:04
  • 1
    https://docs.python.org/3/library/functions.html#open please read docs...two weeks is a long time to find nothing when it is publicly available documentation – ViaTech May 06 '22 at 19:08
  • @ViaTech ah thank you i wasn't thinking and forgot to check if i was using the right mode. hell even now im not thinking straight and cant spell properly. thank you – Bonnie May 06 '22 at 19:19

0 Answers0