我有一个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
就行了,我添加了管道字符。