我有以下代码正在运行99% - 它采取了各种尝试来实现它:
w = csv.writer(filename, lineterminator="\n")
sC = []
for i in sOut:
#print("save", i[1:])
sC.append(i[1:], "\n") #slice away first part
sP = self.ids(sC)
w.writerow(sP)
filename.close()
print("You save ", filename) #To show on CLI
def ids(self, numbering):
tally = 1
for i in range(len(numbering)):
id = str(tally)
numbering[i].insert(0, id)
tally = tally+1
return(numbering)
它应该在CSV文件中返回的输出应该如下所示,即在单独的列中:
1 -4.885276794 55.72986221
2 -4.885276794 55.72958374
3 -4.883611202 55.72958374
相反,它将它全部返回到一行,并带有方括号,逗号和前缀,所有这些都是我不想要的:
['1', -4.88527679443359, 55.7298622131348] ['2', -4.7475008964538, 55.9473609924319] ['3', -4.79416608810425, 56.02791595459]
我知道我在某处犯了一些基本错误,但我不知道是什么?非常感谢所有帮助。
谢谢Jemma
答案 0 :(得分:0)
根据juanpa应该是w.writerows(saveProcess)而不是w.writerow(saveProcess)
一切正常!