Currently, I have
imported csv
and made an input variable for the user to enter a registration. I also have a CSV file called
"Known file reg and names.csv"
I will refer to this as "the doc" with names,addresses and registrations; as seen here:
Bob Job GH58JBL 9, Henderson lane
Dan strobe WK15HYO 12, Dominic Road
Alex Nail VA11ZWU 6, Yake lane
Sam Jones WX63GKP 273, Soomy Avenue
John English WK64HRK 67, Wane Close
I have a program that detects whether an inputted registration in a variable called registration; matches the registration info in the doc.
import csv
registation=str(input("Please enter you registation plate."))
with open('Known file reg and names.csv', 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
for field in row:
if field == registation:
print("We have found your reg in our database")
this works and will result in the program outputting "we have found your reg in our database" when inputting a registration that matches one in the doc.
I then have another chunk of code that is "supposed to" write both the registration variable from the program, and the matching info from the doc to another csv file with that specific persons details.
with open("saved database.csv", "w", newline="") as csvfile:
w = csv.writer(csvfile)
w.writerow([registation])
w.writerow([field])
So if I inputted "WK15HYO" the program should compare the info from the doc and the inputted registration variable, and rewrite that persons info which should be
WK15HYO Dan strobe, 12, Dominic Road
However, this isn't the case and what happens instead is the program writing
67, Wane Close` and WK15HYO
. Its not writing 12, Dominic road and Dan strobe. Please can I receive some insight on what i'm doing wrong and how to solve the problem.
breakout of your for loops. Since you have two of them, you'll need to do something in the inner one (like setting a variable) that the outer one can check and break on as well. You might try it and post updated code, or I've no doubt someone will turn my comment into an answer soon enough.