Home > Software design >  WRITE DATA IN ONE ROW USING CSV
WRITE DATA IN ONE ROW USING CSV

Time:03-18

I want to make excel file using csv :

writer = csv.writer(proxy, dialect='excel', delimiter='\t')

data = ['1','2','3','4']

I want my excel like:

1 | 2 | 3 | 4 |

but now my excel :

1

2

3

4

My code :

for x in data:
   writer.writerow([x])

what should i do to make it in one row only

CodePudding user response:

Don't use a loop.

writer.writerow(data)

Followup

Here's an example.

timr@tims-gram:~/src$ cat x.py
import csv
writer = csv.writer(open('x.csv','w'), dialect='excel', delimiter='\t')
data = ['1','2','3','4']
writer.writerow(data)
timr@tims-gram:~/src$ python x.py
timr@tims-gram:~/src$ cat x.csv
1   2   3   4
timr@tims-gram:~/src$ 
  • Related