0

やあみんなまだここにいる:)

ValueError: I/O operation on closed file エラーが発生します。

db = open(r"C:\Users\PC\Desktop\db.txt", "a+")
print("""-Type 1 for add film
-Type 2 for see your films
""")
while True:
    enter = input("Please Enter: ")

    if enter == "1":
        film=input("Enter film: ")
        db.write(film + "\n")
        db.close()

    elif enter == "2":
        print("Your's films: ")
        db.seek(0)
        print(db.read())

        db.close()



    elif giris == "":
        print("Please type something!")


    else:
        print("Error!")

1 を入力すると、フィルムを追加し、フィルムを表示するために 2 を再度入力します。ValueError: I/O operation on closed file error :(

4

2 に答える 2