仅第一个IF语句运行,其余的则不执行。如果我单独运行它们,它们可以完美地工作,但是总的来说,它们不能工作。提前致谢。
import os.path
filename = input("please enter your file name: ")
if os.path.isfile(filename):
option = input("selec any of the below options \n Read a file: Press R \n Delete a file: Press D \n Append file: Press A \n")
if option == "r" or "R":
readFile = open(filename, "r")
print(readFile.read())
readFile.close()
elif option == "d" or "D":
os.remove(filename)
notesfile = open(filename, "w")
notes1 = input("enter your new data: ")
notesfile.write(str(notes1))
notesfile.close()
elif option == "a" or "A":
with open(filename, "a") as mylife:
mylife1 = input("enter more data data: \n ")
mylife.write(str(mylife1))
mylife.close()
else:
notesfile = open(filename, "w")
notes1 = input("enter your data: ")
notesfile.write(str(notes1))
notesfile.close()