Aug-05-2021, 01:11 PM
I am writing a car rental program on python. In this function I am trying to modify car details which are added in the details.txt file but I am getting an error "if acc[0] == var[0]:TypeError:'NoneType' object is not subscriptable" how do I fix this error ?
def modifying(): global acc exist = False mod_file = open("details.txt") count = 0 for s in mod_file: var = s.split(",") # spilt the data into list var[2] = var[2].strip() if acc[0] == var[0]: exist = True break count += 1 mod_file.close() if exist != True: print("!!! Can NOT Find The Data !!!") elif exist == True: s_list = [] mod_file = open("details.txt", "r") for s in mod_file: s = s.strip() s_list.append(s) mod_file.close choice = "Y" while choice == "Y": print("\n===============================") print("---------- MODIFY Cars ----------") print("---------------------------------") print("Select the details you wish to modify") print("1. Type") print("2. Manufactured Year") print("3. details of the car") print("4. car code") print("5. Daily price rate ( USD $ )") print("6. back") while True: try: c = int(input("please select a number (1 - 5): ")) modify = ["Type", "Manufactured Year", "details of the car", "car code", "Daily price rate ( USD $ )"] if c > 0 and c < 6: new = input("\nType the New " + modify[c - 1] + ":") var[c - 1] = new temp = ",".join(var) s_list[count] = temp mod_file = open("details.txt", "w") mod_file.write("") mod_file.close() count_file = 0 for s in range(len(s_list)): mod_file = open("details.txt", "r") for counting in mod_file: count_file += 1 mod_file.close() mod_file = open("details.txt", "a") if count_file == 0: mod_file.write(s_list[s]) else: mod_file.write("\n") mod_file.write(s_list[s]) mod_file.close() print("\nDetails UPDATED") be_exit = input("\nDo you want to modify again? (Y/N): ").upper() if be_exit == "y": choice = "y" else: modifying(acc) elif c == 6: modifying(acc) else: print("\n!!! Incorrect Input !!!\n") continue except: print("\n!! NOT a Number !!!\n") continue modifying()