Click here to Skip to main content
15,668,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am doing a project for a university course to create a banking app using python. This requires a login and the data to be stored in a CSV.
The issue I have is to iterate through the 2D array that has data from the csv.
Through my debugging the iteration is stopping before the first row and can't seem to figure out how to resolve this.

What I have tried:

This is the current code I have since it is a function. where it has "print(Username)" was only there for testing purposes.

# Function to select which account is being accessed from Accounts.CSV.
def account_select(Username):
    accounts = open('Accounts.csv', 'r')
    print(Username, "1")
    for row in accounts:
        print(Username, "2")
        for column in row:
            print(Username, "3")
            if column[3] == Username:

                print("Username Match")
            if column[3] != Username:
                print("Error Occurred")
Updated 9-Jun-20 10:07am

1 solution

print( # this reads all the lines from your file, but you don't save the result
print(Username, "1")
for row in accounts: # there is nothing to read now, since it has all been read above

Remove the line print( and it should work.

Also, in the following, why not just use else for the second part:
if column[3] == Username:

    print("Username Match")
# if column[3] != Username: this is redundant
# if it does not equal the comparison value then it must be not equal, just use else 
    print("Error Occurred")
Share this answer
Afzaal Ahmad Zeeshan 9-Jun-20 20:35pm    
Richard MacCutchan 10-Jun-20 2:47am    
Thanks Afzaal. Haven't seen you here for a while, have you been working?
Afzaal Ahmad Zeeshan 10-Jun-20 16:30pm    
Hey Richard!

Yes, I started working on a few projects with some clients. What has been taking most of my time is my studies—I started my MS in Computer Science.

I am planning to join the community again, but you know how assignments are. :laugh:

Also, I hope you are safe and healthy during this COVID-19.
Richard MacCutchan 11-Jun-20 4:17am    
Good luck with your degree. We are safe here although missing regular contact with our grandchildren. I am not sure how good or bad things have been in Pakistan, but I hope you are keeping well also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900