0

我有一个这样的列表(python 3)

my_list = [["xxx","moon",150],["wordq","pop",3]]

我使用此代码将其保存在 csv 中

import csv

myfile = open("pppp.csv", 'wb')
with open("pppp.csv", "w", newline='') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_NONE)
    wr.writerows(list_of_DVDsuppliers)

现在我需要将此 csv 作为列表导出到我的程序中并更改数据。请帮我 ?

4

2 回答 2

1

只需将您从 reader() 获得的数据转换为列表:

data = csv.reader(open('example.csv','r'))
data = list(data)
print data
于 2013-10-24T05:51:04.220 回答
0

除非您有使用 newline='' 的理由,否则您可以跳过它,下面的代码适用于 python 2.7,

import csv

my_list = [["xxx","moon",150],["wordq","pop",3]]

myfile = open("pppp.csv", 'wb')
with open("pppp.csv", "w") as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_NONE)
    wr.writerows(my_list)


data = csv.reader(open('pppp.csv','r'))
for row in data:
    print row
于 2013-10-24T05:30:16.400 回答