myfile = open("filename.txt", "a")
myfile.write("Hello, ")
name = input("Enter your name: ")
myfile.write(name)
myfile.close()
myfile = open("filename.txt", "r")
greet = myfile.read()
print(greet)
It is possible to simplify these lines without closing the file? That is, is there an argument for the mode
parameter similar to a "wr"?
Thanks in advance!