I want the block of code under the if-statement to only run if the word "trip" is found in that particular line. However, my print output indicates that even the lines without the word "trip" are in the result. This is the code:
for line in file:
#match = re.search(r'\rTrip', line)
#if match:
if line.find('\rTrip') != -1:
someArray = []
times = re.compile(r'\d+:\d+')
miles = re.compile(r'\d+\.\d+')
names = re.compile(r'[A-Za-z]{2,25}||\s[A-Za-z]{2,25}')
nam = line.split('\rTrip')
num = line.split()
drivenTimes = times.findall(str(num))
drivenMiles = miles.findall(str(num))
driverNames = names.findall(str(nam))
someArray.append(line)
print(line)
Aucun commentaire:
Enregistrer un commentaire