Mar-05-2022, 01:17 AM
Hi there, i have got some set of csv i auto generate and i need advise on the following:
1. i have three labels on the csv ( Serial Number, Starting Code, Key) see the image below
2. from the image above i create
Thanks Greatly in advance
1. i have three labels on the csv ( Serial Number, Starting Code, Key) see the image below
2. from the image above i create
input("")to check if the input keyword is equal to any of the column , if the input is equal to any of the column then print the rest of the cells in the row e.g if
if input == 'KB57000001003', print ('983901181', 'f3e78b3163de11f1dc143082205262e9') and stored them in variable x and y ( x= '983901181' and y = 'f3e78b3163de11f1dc143082205262e9')i have try to do this with csv built in functions but can"t see my code below:
import csv dict = [] file = 'token.csv' search = input("Search Serial number here") inValue = 0 with open(file, 'r') as my_file: reader = csv.reader(my_file) for row in reader: ## this is for serial number for i in range(len(row)): #dict.append(i) if i == 0: print(f'The row number {i} is {row[i]}') dict.append(row[i]) if row[i]== search: inValue = row[i] print(f" Congratulation ! your input is {search} and match with {search} in ") elif i > 0: continue elif i == len(row): break for i in range(len(row)): if i >=1: dict_1.append(row[i]) elif i == len(row): break print('\n') print(inValue) print('\n') print(dict)Out:
Search Serial number here: KB57000001006 The row number 0 is Serial Number The row number 0 is KB57000001001 The row number 0 is KB57000001002 The row number 0 is KB57000001003 The row number 0 is KB57000001004 The row number 0 is KB57000001005 The row number 0 is KB57000001006 Congratulation ! your input is KB57000001006 and match with KB57000001006 in KB57000001006 the list in first Column is ['Serial Number', 'KB57000001001', 'KB57000001002', 'KB57000001003', 'KB57000001004', 'KB57000001005', 'KB57000001006']3. i was only able to scan through the column and get the match but can't print the next two rows in the column, please can you help
Thanks Greatly in advance