-1

结果显示是这样的。我尝试了of方法,无论它似乎无法向上移动。先感谢您

  1. 无论如何,法院阵列是否可以向上移动?
  2. 还是我应该直接删除该行

if __name__ == '__main__': #start of program

    master = Tk()
    newDirRH = "C:/VSMPlots"
    FileName = "J123"
    TypeName = "1234"
    Field = [1,2,3,4,5,6,7,8,9,10]
    Court = [5,4,1,2,3,4,5,1,2,3]
    Field = "\n,,".join(str(x) for x in Field) # to leave a line in each Field array
    Court = "\n,,,".join(str(y1) for y1 in Court) # to leave a line in each Court array
    stringText = "Name, Type, Field, Court\n" + str(FileName) + ',' + str(TypeName) + ',' + Field + '\n,,,' + Court 

    newfile = newDirRH + "/Try.csv"
    text_file = open(newfile, "w")
    x = stringText
    text_file.write(x)
    text_file.close()
    print "Done"

在此处输入图像描述

4

1 回答 1

1

首先请使用CSV 模块来编写 CSV。其次,用于zip创建 Field / Court 对的列表,例如

>>> Field = [1,2,3,4,5,6,7,8,9,10]
>>> Court = [5,4,1,2,3,4,5,1,2,3]
>>> zip(Field, Court)
[(1, 5), (2, 4), (3, 1), (4, 2), (5, 3), (6, 4), (7, 5), (8, 1), (9, 2), (10, 3)]

您可以按如下方式遍历此列表:

for field, court in zip(Field, Court):
    stringText = ','.join((FileName, TypeName, field, court))
于 2013-10-11T06:19:27.170 回答