我正在尝试检查csv文件中的特定数据,然后让它打印整行。
代码:
import csv
from datetime import *
Date = date.today()
strDate = str(Date)
File = (strDate + ".csv")
count = 1
with open(File, "r") as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in csvreader:
if row[0] == ("1"):
print(row)
正在读取的文件包含:
1,Test1,2015-10-19
2,Test2,2015-10-19
错误代码:
>>>
['1', 'Test1', '2015-10-19']
Traceback (most recent call last):
File "C:/Users/ntaylor/Desktop/St Thomas More Log in/File Read Test.py", line 14, in <module>
if row[0] == ("1"):
IndexError: list index out of range
>>>
我相信这个问题并不重复,因为人们在“重复”问题中给出的答案不适合或修复我的问题。
任何帮助都会有用,谢谢。