So im trying to iterate through csv file such as the following:
time date
25:07 40
0:07 3
0:67 1
0:26 -1
-1:26 4
and in the end i have to generate a list with the proper constraints. if its not in the proper constraint then the row wouldnt be generated in the end. the constraints are as this: 1. Illegal time value structure (not HH:MM) and illegal time value (HH < 0 or HH> 23, MM < 0 or MM > 59). 2. Illegal date value (date < 1 or date > 31).
this is what i have tried:
atm_transaction_time_date = []
my_file = open("atm_file_time_date", "r")
reader = (csv.reader(my_file))
header = my_file.readline()
#to check for illegal time
for line in reader:
if ':' not in (line[0]):
continue
elif int(line[0].split(':')[0]) < 0 or int(line[0].split(':')[0]) > 23:
continue
else:
return (line[0].split(':')[0])
if ':' not in (line[0]):
continue
elif int(line[0].split(':')[1]) < 0 or int(line[0].split(':')[1]) > 59:
continue
else:
return (line[0].split(':')[1])
#to check for illegal date
if 0 > int(line[1]) > 31:
continue
else:
return int(line[1])
atm_transaction = (str(line[0]), int(line[1])
atm_transaction_time_date.append(atm_transaction)
my_file.close()
return atm_transaction_time_date
but it still didnt work. this is the error message Error TypeError : unorderable types: str() < int() raised in function elif (line[0].split(':')[0] < 0) or (line[0].split(':')[0]) > 23: