-1

I'm making a program that lets you input data into a CSV file and then let you search for specific customers, and delete specific customers from the system. I've done the viewing part but I can't figure out how to overwrite a specific line in the csv file. This is what I have so far:

    choice = str(input("What would you like to do?"))
    if choice.lower() == "delete":
        Type = str(input("Type in 'Phone' to delete by Phone number and 'Name' to delete by Surnames: "))
        if Type.lower() == "phone":
            view = str(input("Enter the phone number of the customer you want to delete: "))
            check = csv.reader(open('D:\Programming\School Work\Johns Decorating company program\Customers.csv', "rt"), delimiter=",")
            for line in check:
                if view in line:
                    print(line)
                    confirm = str(input("Type 'Yes' to delete all of the quotes above. Type 'No' to restart or to select in a different way"))
                    if confirm.lower() == "yes":
                        #!THIS IS WHERE I'M CONFUSED!
                    elif confirm.lower() == "no":
                        print("Restarting search")
                        existing()

1 Answers1

0

You can transform csv to a list and write:

for i in range(len(check)):
  if check[i][column_index] == phone_number:  # column_index is index
                                              # of a column where the phone numbers are stored
   del csv_list[i]

I hope this helps you.

Novak
  • 2,143
  • 1
  • 12
  • 22