1

下面的代码允许我实现这个结果,但是

  1. 我希望文件名和类型像旁边的图片一样,只包含一个。
  2. 有没有办法解决这个问题?

在此处输入图像描述在此处输入图像描述

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"
4

1 回答 1

2

在第一次循环迭代后将 , 设置为空FileName字符串。TypeName

...
for field, court in zip(Field, Court):
    writer.writerow([FileName, TypeName, field, court])
    FileName = TypeName = '' # <---
...
于 2013-10-11T08:43:18.033 回答