I am making a file editor with python idle. I have a part where if the file requested doesn't exist it inserts "No such file exists" in the text box (textA). However instead of giving the error message a file is created. My code is:
def addtofile():
    name = entryA.get()
    try:
        file = open(name, "a")
        content = entryB.get()
        file.write(content)
        file.close()
        windowa.destroy()
        start()
    except:
        content = "No such file exists"
        textA.delete(0.0, END)
        textA.insert(END, content)
I open the file using 'a' so the previous content doesn't get erased. I think the issue is with how I am opening the file. Can you tell me how to open (I know 'a', 'r', 'w' and 'w+') the file where it doesn't overwrite previous content but doesn't create a file if one doesn't exist?
 
     
    