0

I have simple code written in python. while writing into an excel file. I found additional rows get added each time. How can I skip the empty row added each time. and print data one after the other in an excel file

import csv
from datetime import datetime
import time

filename = 'testformat.csv'
fields = ['SLNo', 'Date', 'Time', 'RData', 'BData', 'GData', 'IRData']
date_format = datetime.now().strftime('%Y/%m/%d')
current_time = datetime.now().strftime('%I:%M:%S,%f')

def main():
    with open(filename, 'w') as csvfile:
        csvwriter = csv.writer(csvfile)
        csvwriter.writerow(fields)
        for i in range(30):
            csvwriter.writerow([i, date_format, current_time])
if __name__ == '__main__':
    main()
user3551354
  • 39
  • 1
  • 7

1 Answers1

1

What you need is already here : https://stackoverflow.com/a/3191811/18081892

You have to use :

with open(filename, 'w', newline='', encoding='utf-8') as csvfile:
niavlys
  • 38
  • 1
  • 6