Ju Chu
Ju Chu

Reputation: 9

Python written CSV is limited by 5 rows

I'm trying to export numbers in row of csv. However, doesnt matter if I want to print it in row or columes, they are all limited by size 5. If the writer exccess 5 , it will rewrite them again. I want csv to record all lines I want to write, not only last 5 lines. This is the code I wrote:

with open('Testing.csv', 'w', newline='') as file:
        writer = csv.writer(file)
        writer.writerows(str(lencenters))

and this is the csv I got:

Upvotes: 0

Views: 101

Answers (2)

Sergiy Galaburda
Sergiy Galaburda

Reputation: 21

Try not to convert the lencenters to str like

writer.writerows(lencenters)

The lencenters should be a list of lists representing row fields.

Upvotes: 1

Renaud
Renaud

Reputation: 2819

It works for me with:

import csv

with open('Testing.csv', 'w', newline='') as file:
    writer = csv.writer(file)
    for i in range(0,20):
        writer.writerows([[i]])

Upvotes: 0

Related Questions