sorry if this isn't clear, or if this is simple, I'm a complete newbie at this. I have this python code:
identer = input("Enter your Student ID... ") passenter = input("Enter your password... ") with open("pupil.csv", "r") as f: reader = csv.reader(f) for row in reader: if identer != row["student_id"] or passenter != row["password"]: print("Wrong ID or Password, try again.") else: The line if identer != row["student_id"] or passenter != row["password"]: is throwing the error:
TypeError: list indices must be integers or slices, not str Is there a solution here I'm blind to? Here is the CSV file, if it helps.
forename,surname,phone_no,email,password,student_id,account_balance,module1,module2 nathan,m,099099,ddd,12345,754,100,, reg,beg,180,regb,0987,331,100,, g,b,334,email,911,203,100,, Edit: This is my code with dictreader
identer = input("Enter your Student ID... ") passenter = input("Enter your password... ") with open("pupil.csv", "r") as f: reader = csv.DictReader(f) for row in reader: if identer != row[student_id] or passenter != row[password]: print("Wrong ID or Password, try again.") else: This time it is throwing an error saying "KeyError: 754" 7d4 being the id
https://stackoverflow.com/questions/65589381/cant-get-relative-password-and-id-from-csv-file January 06, 2021 at 10:29AM
没有评论:
发表评论