I have a csv file that has 3 columns. I am trying to search the second column for a specific value (hexadecimal values) and read the next record in this row (column 3). The format is similar to the one below:
Text1, 0x04d0a053, value1 Text2, 0x04d01053, value2 Text3, 0x04d03053, value3 Text4, 0x04d05053, value4 Text5, 0x04d00053, value5 Text6, 0x04d02053, value6 Text7, 0x04d04053, value7 Text8, 0x04413053, value8
I have no problem finding and reading the last value (0x04413053) and printing "value8". However, when I try to search for any of the first 7 records, nothing is read ([] in the output). My code is below, who has an idea of ββwhat might be a bug?
fileInput = 'mycsv.csv' column0 = 0 column1 = 1 column2 = 2 #reads correctly hexvalue = hex(0x04413053) with open(fileInput, 'r') as file: reader = csv.reader(file) entry = [line[column2] for line in reader if line[column1] == hexvalue] print entry #does not read correctly hexvalue = hex(0x04d0a053) with open(fileInput, 'r') as file: reader = csv.reader(file) entry = [line[column2] for line in reader if line[column1] == hexvalue] print entry
Hoser source share