I'm writing a program in Python where you can write to a text file from the program, remotely. Relevant Code:
namein = input("What do you want the filename to be? Don't include an extension...\n")
extin = input("What would you like the extension to be? This program supports:\nMicrosoft Word Document: '.docx'\nPlain Text File: '.txt'\nRich Text File: '.rtf'\nPages Document: '.pages'\n")
aw = input("Do you want to append your text file, or rewrite the whole thing? (append/write) ")
if aw == 'append':
textin = input("In the line below, write the text you want to put into your text document!\n\n")
outfile = open(namein + extin, 'a')
outfile.write(textin)
outfile.flush()
print("Great! Now your text file has been updated!")
print("Your text file:\n")
outfile.close()
outfile = open(namein + extin, 'r')
print(outfile.read())
When someone chooses a non '.txt' file, one can't open the file! It just says error, the file can't be opened. Is there a way around this?