I am working on a python script that reads user input and returns values from the CSV. I am able to return all values, but I only need a few. There are many columns in the CSV, examples are:
LOC_NBR LOC_NAME ALPHA_CODE FRANCHISE_TYPE FRANCHISEE_LAST_NAME
My code is below, what could I add to this to only pull the data for say LOC_NBR, LOC_NAME, and FRANCHISE_TYPE? Right now if I change the print statement, I get a data type error because the fields are STR in the csv.
import csv
store_Num = input("Enter 5-Digit Store Number: ")
with open('StoreDirectory.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
found = False
for line in reader:
if line[0] == store_Num:
print(line)
found = True
break
if not found:
print(store_Num, "not found")
csv.DictReader(). If the file has a header then you do something likeline["LOC_NBR"].