0

i'm doing an exercise for school where you use python to store client details in a csv and i'm having trouble with adding a way for the user to delete their client details as pop won't accept anything but an index number - can someone help me find a way to do this? I'm really new to coding sorry.

Here's my code:

if first_name in name:
    for x in range(0,len(existing_clients)):
        if first_name == existing_clients[x][0]:
            print(existing_clients[x])
            index = existing_clients.index(existing_clients[x])
            print(index)
            existing_clients.pop(index)

The above works to print out the index number but I don't know how to make it delete the client details from the list/csv. I feel like i'm missing something really obvious and stupid.

Here's an example of the csv data making up existing_clients:

Ave,O' Hogan,Ms,Male,13/04/2022,Help Desk Operator,1285.66,64.80
Ariel,Fidge,Honorable,Female,15/09/2022,VP Quality Control,8.27,82.63
Timoteo,McGowing,Dr,Male,03/12/2021,General Manager,1751.11,23.92
Lezley,Wilmott,Mr,Male,04/07/2022,Statistician I,350.05,74.83
  • Welcome to SO. Try producing [a minimal code](https://stackoverflow.com/help/minimal-reproducible-example) sample for users to reproduce and answer the issue. Regarding your question, how are you reading the CSV file? – Roxy Nov 17 '22 at 13:32
  • I have a bit of code in the beginning of the program: ``` existing_clients = [] with open("mock_data.csv") as csvfile: reader = csv.reader(csvfile) for row in reader: existing_clients.append(row) ``` – LetMeLive Nov 17 '22 at 13:38
  • adapt the above-mentioned snippets to edit your question and provide full reproducible code. You can find more details here on [how to format](https://stackoverflow.com/help/formatting). – Roxy Nov 17 '22 at 14:01

0 Answers0