以下代码允许我实现此结果,但
if __name__ == '__main__': #start of program
master = Tk()
newDirRH = "C:/VSMPlots"
FileName = "J12312312"
TypeName = "1234"
Field = [1,2,3,4,5,6,7,8,9,10]
Court = [5,4,1,2,3,4,5,1,2,3]
newfile = newDirRH + "/Try1.csv"
with open(newfile, "wb") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["FileName", "TypeName", "field", "court"])
for field, court in zip(Field, Court):
writer.writerow([FileName, TypeName, field, court])
print "Done"
答案 0 :(得分:2)
在第一次循环迭代后将FileName
,TypeName
设置为空字符串。
...
for field, court in zip(Field, Court):
writer.writerow([FileName, TypeName, field, court])
FileName = TypeName = '' # <---
...