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?

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()

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.