我有以下标题的预订 CSV 文件:名字、姓氏、预订日期、主题、课程时间、班级人数我想阅读 CSV 文件,只打印预订日期为“(特定值)”和课程时间为“(特定值”)的行到目前为止,我的代码是:check_date = "11/01/2019"check_period = "Lesson 3"with open("Bookings.csv") as f: reader = csv.reader(f) header = next(reader) found = False for line in reader: if line[2] == check_date and line[4] == check_period: for line in reader: print(line) found = True break if not found: print("No bookings for", check_date, " ", check_period)但是,不是输出日期为“11/01/2019”且课程时间为“第 3 课”的行 - 而是使用此标准打印第一行,忽略其余行,并在此之后打印下一行。下面的屏幕截图:(显示代码、输出和 CSV 示例)
添加回答
举报
0/150
提交
取消