我有一個2-D列表myList [r] [c],其中有r
列各有c
列。Python二維列表:導出爲分隔文本文件
我試圖將其導出到一個文本文件中,每個列元素由管道分隔| ,並在每行末尾加上&符號&。
myList = [[[] for a in range(c)] for b in range(r)]
{a bunch of code populating myList}
f = open("myfile.txt","w")
for x in range(0,r):
thisRow = ''
for y in range(0,c):
appendThis = myList[x][y]
thisRow += appendThis + "|"
f.write(thisRow)
f.write("&")
f.close
...但我得到TypeError: can only concatenate list (not "str") to list
就行了,我添加了管道字符。