import csvimport timedef timestamp_to_timestr(timeStamp): timeArray = time.localtime(int(timeStamp)) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) return otherStyleTimef=open('C:/look.csv','r')reader = csv.DictReader(f)headers = reader.fieldnameslook = list(reader)f=open('C://up.csv','r')up= list(csv.DictReader(f))f.close()for l in up: l['start_time'] = timestamp_to_timestr(l['start_time']) l['end_time'] = timestamp_to_timestr(l['end_time'])for r in look : for s in up: if r['look_id'] == s['look_id'] and r['last_update_time'] >= s['start_time'] and r['last_update_time'] < s['end_time']: r['up_id'] = s['up_id'] breakwith open('C:/lookup.csv','w') as f: f_csv = csv.DictWriter(f, headers, lineterminator='\n') f_csv.writeheader() f_csv.writerows(look)