我有一个电子表格,其列为:1,2,3,5 ... 100。
在我的代码中,我可以搜索每一列。上面的列是第8列。我希望能够打印行值和它下面的行。我用过:
print row[8 + 1]
所有这些似乎都是打印行值,然后添加一个。但是,我想要做的是使用:
print row[8]
print row[8 + 1]
哪个会打印出一个值和
下面的值完整代码:
i
mport csv
import string
with open("testercsv.csv", "rb") as f:
reader = csv.reader(f)
#Error log file
log_error = open("lewis.txt", 'a')
#Checking row
next(f, None)
next(f, None)
for row in reader:
#row 1
if (row[1]) == "2":
print "Found: ", "2"
else:
log_error.write("Found: ")
log_error.write(row[1])
log_error.write(" Expected: 2")
log_error.write("\n")
#row 2
if (row[2]) == "0":
print "Found: ", "0"
else:
print "0 error"
#row 3
if (row[3]) == "LIVE":
print "Found: ", "LIVE"
else:
print "LIVE error"
#row 4
if (row[4]) == "2":
print "Found: ", "2"
else:
print "2 error"
#row 5
if (row[5]) == "0":
print "Found: ", "0"
else:
print "0 error"
#row 6
if (row[6]) == "1":
print "Found: ", "1"
else:
print "1 error"
#row 7
if (row[7]) == "0":
print "Found: ", "0"
else:
print "0 error"
#Checking count row 8
print row[8+1]
答案 0 :(得分:0)
for i in range(0,100):
print(row[i])
print(row[i+1])