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中的最后一个空行?在
Tags:
只是一个重新排序的问题:
听起来你的输入文件中有一个空行。从您的注释来看,实际上有一个非空行,其中没有
|
个字符。无论哪种情况,检查结果行是否为空都很容易。在试试这个:
其他注意事项:
with
。以相同的方式打开两个文件。在str(row)
是no-op。row
已经是strstr(','.join(...))
同样是冗余的。在open(..., 'read')
不是open()
的模式参数的有效使用。您应该使用r
,甚至完全忽略该参数。在row = row.split()
,而不是{以下是一个包含以下建议和其他建议的版本:
^{pr2}$相关问题 更多 >
编程相关推荐