Harry Beggs
Harry Beggs

Reputation: 71

Python 2.7 csv format incorrect

I am currently trying to write a list of scores called scores_int to a csv file. I want to make my csv file in this format:

https://gyazo.com/225685fc5e2d71426791ef55c92007d0

but it is currently being written in this format:

https://gyazo.com/8b1e374b6601f5a4025365975383c8c7

Here is my code for the write:

with open("srt_Scores.csv", "w") as sortfile:   #Should write a new csv file every time containing the sorted scores
    w = csv.writer(sortfile, delimiter = ",")
    w.writerows([[v] for v in scores_int])

crashed = True

If anyone could help me it would be much appreciated, thanks.

Upvotes: 1

Views: 33

Answers (1)

lakeIn231
lakeIn231

Reputation: 1315

Use "wb" instead of "w" because you need to open it as a binary file.

with open("srt_Scores.csv", "wb") as sortfile:   #Should write a new csv file every time containing the sorted scores
    w = csv.writer(sortfile, delimiter = ",")
    w.writerows([[v] for v in scores_int])

crashed = True

Upvotes: 1

Related Questions