運行
我正在Python版本3.5,從命令提示符在Windows 7Python - 爲什麼我的.read()不能在我的.txt文件上工作?沒有什麼是輸出到CMD線
什麼是.txt文件,什麼CMD輸出
我當前的代碼
"""Opens a file and let\'s you read it and write to it"""
open_pls = open("text.txt", "a+")
#Main function
def read_write():
program_running = True
while program_running == True:
choice = input("Write R for read, write W for write or write X for exit:")
choice = choice.upper()
if choice == "W":
what_write = input("What do you want to write to the end of the file?:")
open_pls.write(what_write)
print("Succesfully written!")
print("Running program again...")
continue
elif choice == "R":
print("This file contains:")
read_pls = open_pls.read()
print(read_pls)
print("Running program again...")
continue
elif choice == "X":
program_running = False
open_pls.close()
else:
print("That was not a valid command!")
print("Running program again...")
continue
run = input("Run the program? (Y/N):")
run = run.upper()
if run == "Y":
read_write()
elif run == "N":
input("Exit program? Press enter:")
else:
input("Exit program? Press enter:")
我認爲問題出在某處這裏
elif choice == "R":
print("This file contains:")
read_pls = open_pls.read()
print(read_pls)
print("Running program again...")
continue
謝謝,我現在明白了:) –