Skip to content Skip to sidebar Skip to footer

List Export And Import From Csv

i need to save 6 lists in csv file and load back when program open.help me please this is one of my list and all the lists are updating these are some sample details list_of_DVDsu

Solution 1:

You want

wr.writerows(list_of_DVDsuppliers)

with an s, because you're writing more than one row.

As well,

myfile.close

doesn't do anything: you want

myfile.close()

to actually call it, not merely mention the name.

Better would be to use a with block:

withopen("pppp.csv", "wb") as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_NONE)
    wr.writerows(list_of_DVDsuppliers)

because then you never have to remember to close the file, it's done automatically.


This produces a file looking like

a,m,15
w,p,34

which I'm guessing is what you want (you might want the list flattened and written as one row instead.)

[PS: I'm assuming Python 2 here. Othewise it should be open("pppp.csv", "r", newline='').]

Post a Comment for "List Export And Import From Csv"