0

I try to write array to file:

import csv
ofile = open('result.csv', "w")

writer=csv.writer(ofile, delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL)
a=[[1,2],[3,4]]
for i in a:
    writer.writerow(i)
ofile.close()

the target file will be:

1,2

3,4

I want to write file without mid empty line here

I want:

1,2
3,4

How should I do it?

user504909
  • 9,119
  • 12
  • 60
  • 109

1 Answers1

0

Looks like you're on Python 2.x.

Open the file in 'wb' mode instead of 'w' so change this line ofile = open('result.csv', "w") to this ofile = open('result.csv', "wb"). That should fix the problem

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34