0

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 ?

4
  • 1
    Did you save it to a single line because you want to flatten the list? Commented Oct 24, 2013 at 5:30
  • its saved like this xxx,moon,150 wordq , pop ,3 Commented Oct 24, 2013 at 5:34
  • 1
    Yeah, but why? You must've had some purpose. Commented Oct 24, 2013 at 5:41
  • ya if its not csv file store data skiping 1 row Commented Oct 24, 2013 at 6:34

2 Answers 2

1

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

data = csv.reader(open('example.csv','r'))
data = list(data)
print data
Sign up to request clarification or add additional context in comments.

Comments

0

Unless you have a reason why you are using newline='', you can skip that and below code works with 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

7 Comments

What about the newline='' part?
i dont no about that.cos my friend teach me to do so,and is ther's a way to restore csv data(when i re open my program) in my_list ?
and this error occurs to your code data = csv.reader(open('pppp.csv,'r')) ^ SyntaxError: EOL while scanning string literal
I do not see an option of newline in 2.7 anyway.
nop not working its python 3.3 and really me need is when i restart the progam i want to restore the csv data in my_list?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.