Hi I want to save a dictionary to csv, then input it. However on both output and input, I met some issues.
For output I tried: (D_FINAL is the dictionary)
f = open("D_FINAL.csv", "w")
writer = csv.writer(f)
for k, v in D_FINAL.items():
writer.writerow([k, v])
f.close
It works fine but when I want to open the csv, it says the file is locked from editting
For input I tried
import csv
dict = {}
r = open('D_FINAL3.csv', 'r')
for k, v in csv.reader(r):
dict[k] = v
r.close()
but I got error
ValueError Traceback (most recent call last)
<ipython-input-92-d3e2b3081317> in <module>()
3 dict = {}
4 r = open('D_FINAL2.csv', 'r')
----> 5 for k, v in csv.reader(r):
6 dict[k] = v
7
ValueError: not enough values to unpack
(expected 2, got 0)
What's the correct way to do these ?