我如何删除空白行输出时使用python写入logging到csv而不写在csv中存在的所有logging?

我一直试图删除我的CSV文件中的logging之间的空白行使用Python而不擦除整个电子表格。

import csv, os def display(file): # this procedure displays file and returns the last ID f=csv.reader(open(file,'r')) for i in f: ID = i[0] print i return ID def newentry(file, rec): # this writes the rec to the file f=csv.writer(open(file,'a')) f.writerow(rec) #-------------------------------------- ''' this is the main program that - 1. creates the next ID value 2. takes the inputs for record to be written 3. define the record in the correct order ''' #---to append a new entry with the next value for ID n = input("Enter number of records to add:") for i in range(n): ID=int(display('records.csv'))+1 fname=raw_input("Please enter the First Name:") sname=raw_input("Please enter the Surname:") hnumber=raw_input("Please enter the house name or number:") street=raw_input("Please enter the name of the street:") area=raw_input("Please enter the area:") county=raw_input("Please enter the County:") pcode=raw_input("Please enter the Postcode:") tel=raw_input("Please enter the contact number:") rec=(ID,fname,sname,hnumber,street,area,county,pcode,tel) newentry('records.csv', rec) #---- to display the file for confirmation display('records.csv') 

这会创build像这样的logging:

 1,dave,davidson,1,avenue,somewhere,somewhere,pppppp,0111111111 2,jeff,jefferson,3,street,overthere,overhere,tttttt,0222222222 

但我需要它在Excel中显示这样的:

 1,dave,davidson,1,avenue,somewhere,somewhere,pppppp,0111111111 2,jeff,jefferson,3,street,overthere,overhere,tttttt,0222222222 

我做错了什么?