无法使用python删除文件的最后一行

时间:2019-05-09 19:05:48

标签: python

我下面创建了多个csv文件,并在每个文件的末尾放置了一个字符。 当我打开每个文件时,我注意到有一条额外的行,我尝试使用

删除它

[:-1]

但不起作用

 newlist = list(chunks(weblinks, 10))
 #PUT EACH LIST INTO FILE
 count = 0
 for nl in newlist:
     if nl:
         #CREATE FILE NUMBERING
         count=count+1
         with open('sktz'+str(count)+'.csv','w',encoding='utf-8',newline='') as f:
             writer = csv.writer(f, delimiter=";")
             #PLACE ON LAST ELEMENT A >
             last_elem = nl[-1]
             last_elem[1] = last_elem[1]+'>'
             nl[-1] = last_elem

             for each_elem in nl:
                 if each_elem:
                     writer.writerow(each_elem)
                     #writer.writerow(each_elem[:-1])

0 个答案:

没有答案