Python 2.7 csv格式错误

时间:2017-03-13 21:35:41

标签: python csv

我目前正在尝试将一个名为scores_int的分数列表写入csv文件。我想以这种格式制作我的csv文件:

https://gyazo.com/225685fc5e2d71426791ef55c92007d0

但目前正在以这种格式编写:

https://gyazo.com/8b1e374b6601f5a4025365975383c8c7

这是我写的代码:

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

如果有人能帮助我,我将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:1)

使用" wb"而不是" w"因为您需要将其作为二进制文件打开。

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