【发布时间】:2016-08-09 18:22:20
【问题描述】:
nf=open(Output_File,'w+')
with open(Input_File,'read') as f:
for row in f:
Current_line = str(row)
Reformated_line=str(','.join(Current_line.split('|')[1:-1]))
nf.write(Reformated_line+ "\n")
我正在尝试读取表格格式的Input file 并将其写入 CSV 文件,但我的输出还包含最后一个空行。如何删除 CSV 中的最后一个空行?
【问题讨论】:
-
旁白:您使用
with打开一个文件而不打开另一个文件有什么原因吗?另外,你为什么打电话给str(row)?由于row已经是str,这似乎没有任何用处。