我正在尝试将列表列表写入新文件,但我收到此错误:
回溯(最近一次调用最后一次):文件"",第1行,在dowork()文件"C:\ Python27\work\accounting\formatting quickbooks file\sdf.py",第11行,在dowork中WriteFile()文件"C :\ Python27\work\accounting\formatting quickbooks file\sdf.py",第71行,在WriteFile中.frite(thefile)TypeError:期望一个字符缓冲区对象
如何将列表列表写入文件?
这就是我写作的方式:
def WriteFile():
global thefile
f = open("output"+'.csv','w')
f.seek(0)
f.write(thefile)
f.close()
Run Code Online (Sandbox Code Playgroud)
如果您需要,这里是完整的来源:
import csv
thefile = []
output = []
def dowork():
sourceFile='e.csv'
thefile=ReadFile(sourceFile)
CleanFile(sourceFile)
ProcessFile()
WriteFile()
def ReadFile(filename):
return list(csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"'))[1:]
def CleanFile(sourceFile):
global thefile
thefiletmp=[]
for i, line in enumerate(thefile):
if line[2]=='':
del thefile[i]
else:
thefiletmp.append(line[4:])
thefile=thefiletmp
def ProcessFile():
global thefile
iCompany=1
iNum=0
iDate=2
iAging=3
iBalance=4
COMPANIES=GetDistinctValues(1)
mytemparray=[]
mytempfile=[]
for company in COMPANIES:
for line in …Run Code Online (Sandbox Code Playgroud)