如何从csv作为列表导出数据(python 3) [英] How to export data from csv as a list(python 3)

查看:428
本文介绍了如何从csv作为列表导出数据(python 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的列表(python 3)

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

使用此代码

  import csv 

myfile = open(pppp.csv,'wb' )
with open(pppp.csv,w,newline ='')as myfile:
wr = csv.writer(myfile,quoting = csv.QUOTE_NONE)
wr。现在我需要将这个csv作为列表导出到我的程序中,并更改列表中的csv文件。数据。
请帮帮我?

解决方案

将从reader()获取的数据转换为列表:

  data = csv.reader(open('example.csv','r'))
data = list(data)
打印数据


I have a list like this(python 3)

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

and i save it on a csv using this code

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)

now i need to export this csv in to my program as a list and change the data . please help me ?

解决方案

Just convert the data you get from reader() to a list:

data = csv.reader(open('example.csv','r'))
data = list(data)
print data

这篇关于如何从csv作为列表导出数据(python 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆