【发布时间】:2020-08-07 17:38:26
【问题描述】:
我正在尝试在 python 的列表中添加新行以向我的文本文件写入任何建议?
header = ['Employee ID','Type','Routing Number','Account Number']
header.append("\n")
strOtherLine = [strSsn,strThisType,strThisRoute,strThisAcct]
header.append("\n" + strOtherLine)
fc_otherfile = r"c:\******\*****\gah\\" + strOtherSavedFile
#===Writing to the text file
with open(fc_otherfile,'w', newline='') as t:
dirdep = csv.writer(t, delimiter="\t")
dirdep.writerow(header)
这是我在文本文件中得到的:
Employee ID Type Routing Number Account Number "" ['###########', 'Checking', '###########','###########'] ['###########', 'Checking', '###########', '###########']
但我想要的是这样的:
Employee ID Type Routing Number Account Number
########### Checking ########### ###########
########### Checking ########### ###########
【问题讨论】:
标签: python-3.x csv