I'm having a lot of difficulty understanding the difference between csv.reader and csv.dictReader. The Python docs didn't shed much light for me on this point...
Basically when would I elect to use csv.reader and where is csv.dictReader the better choice (I feel the answer must relate to
So my questions are :
1) what is the difference between the two methods?
2) my code reprints the fieldnames when I use csv.dictReader
3) rightnow my fieldnames are in my csv file...how do I attach them to print with csv methods
(for example with csv.dictWriter it is
here is my csv:
Basically when would I elect to use csv.reader and where is csv.dictReader the better choice (I feel the answer must relate to
fieldnames?So my questions are :
1) what is the difference between the two methods?
2) my code reprints the fieldnames when I use csv.dictReader
3) rightnow my fieldnames are in my csv file...how do I attach them to print with csv methods
(for example with csv.dictWriter it is
fieldnames=['id','a','b','c','d']; somefile = csv.DictWriter(someotherfile, fieldnames=fieldnames];somefile.writeheader() what is csv.reader/csv.dictReader alternative?here is my csv:
Output:id-a-b-c-d
1-foo-1-2-0
2-bar-10-20-0
3-moo-2-3-0here is my code:opened_file = open('foo0.csv')
print(opened_file.read())#this prints out fine
with open('foo0.csv') as openme:
#also, how do I implement fieldnames with csv.reader OR csv.dictReader (the docs show me how to do this with csv.dictWriter only)
readme = csv.DictReader(openme, delimiter='-')#this refuses to work...it simply reprint my 'fieldnames'
for x in readme:
print(' '.join(x))my output:Output:id-a-b-c-d
1-foo-1-2-0
2-bar-10-20-0
3-moo-2-3-0
id a b c d
id a b c d
id a b c d
