I currently have;
files = ['a.txt', 'b.txt', 'c.txt']
ftypes = [['a', 'b'], ['c'], ['a', 'b', 'c']]
with open('files.csv', 'wb') as file:
writer = csv.writer(file, quoting=csv.QUOTE_MINIMAL)
for f, g in zip(files, ftypes):
writer.writerow((f, g))
to read it in I've used;
with open('files.csv', 'r') as rfile:
csvread = csv.reader(rfile)
files = []
ftypes = []
for row in csvread:
files.append(row[0])
ftypes.append(row[1])
In the actual csv, the second column is populated correctly with the sub-lists filling the 2nd column, however upon reading in ftypes, it returns ["['a', 'b']", "['c']", "['a', 'b', 'c']"] which is incorrect. It treats it as a list of strings, so I can't loop through them like so;
for i in ftypes:
for j in i:
print(j)
How do I fix my writing/reading so that the nested list parses correctly?
Edit:
CSV file contents
a.txt,"['a', 'b']"
b.txt,"['c']"
c.txt,"['a', 'b', 'c']"
It appears as though Excel 2013 is parsing the double quotes and ignoring them, but python is parsing the actual csv contents correctly. What parameters do I need to pass into csv.writer to correct this?