|
我从文件中提取了一些数据,并准备将其写入另一个文件。但我的程序返回错误:
sequence item 1: expected string, list found
报错的代码如下
- file = open('file1.txt','r')
- file2 = open('file2.txt','w')
- buffer = []
- rec = file.readlines()
- for line in rec :
- field = line.split()
- term1 = field[0]
- buffer.append(term1)
- term2 = field[1]
- buffer.append[term2]
- file2.write(buffer) # <== error
- file.close()
- file2.close()
复制代码
|
|