0

I have an issue while creating a CSV file using the CSV module

csvFp = csv.writer(open(fileName,"w"), delimiter=',') 
csvFp .writerow('1')
csvFp .writerow('2')
csvFp .writerow('3')

When i execute the above code,it creates the CSV file correctly but a blank line is inserted between each row eventhough i have not inserted that in the code.

Why is it happening?

2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by meensatwork
0

Default lineterminator is '\n\r'

import csv
def main():
    filename = 'test.txt'
    csv_fp = csv.writer(open(filename,"w"), delimiter=',', lineterminator='\n')
    csv_fp.writerows([['1', '2', '3'],[4,5,6]])

if __name__ == '__main__':
    main()
0

Thank you so much. I was breaking my head for the past couple of days about this problem.Then i posted here hoping i will get a solution definitely.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.