Python Forum
I am writing a car rental program on python. In this function I am trying to modify
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am writing a car rental program on python. In this function I am trying to modify
#1
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()
buran write Aug-05-2021, 03:31 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Please, post the entire traceback that you get. We need to see the whole thing. Do not just give us the last line.
Take a time to read What to include in a post
Reply


Messages In This Thread
I am writing a car rental program on python. In this function I am trying to modify - by aboo - Aug-05-2021, 01:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Function parameter not writing to variable Karp 5 955 Aug-07-2023, 05:58 PM
Last Post: Karp
Question Help me modify this .txt into .csv with Python mgzz 1 751 Dec-14-2022, 01:38 PM
Last Post: Axel_Erfurt
  Create a function for writing to SQL data to csv mg24 4 1,179 Oct-01-2022, 04:30 AM
Last Post: mg24
  Noob here. Random quiz program. Using a while loop function and alot of conditionals. monkeydesu 6 1,411 Sep-07-2022, 02:01 AM
Last Post: kaega2
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,233 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Writing into 2 text files from the same function paul18fr 4 1,691 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  Writing on an lcd display gives problems to the program Idontknowany 1 1,423 Nov-15-2021, 10:46 PM
Last Post: Larz60+
  Writing a lambda function that sorts dictionary GJG 1 2,035 Mar-09-2021, 06:44 PM
Last Post: buran
  Writing a function to calculate time range in Unix Epoch Time t4keheart 2 3,023 Jul-15-2020, 01:55 AM
Last Post: t4keheart
  Modify code from running program ? samuelbachorik 2 2,455 Jun-26-2020, 08:17 PM
Last Post: samuelbachorik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020