file - (Python) How do I append something that is not in a notepad? -


i trying append new line notepad if line not in notepad. let's notepad called 123.txt , inside notepad is:

 3  2  1 

i want input 4,3 123.txt 4 appended:

 4  3  2  1 

i tried doing doesn't work:

 append_note = open(123.txt, "a")  if line not in open(123.txt, "r").read().split("\n"): # line mean 4,3       line_to_write = line + "\n"       append_note.write(line_to_write) 

how should change make work?


Comments