Note that there are some explanatory texts on larger screens.

plurals
  1. POPython's csv DictReader returns "None" for field values; Any ideas?
    primarykey
    data
    text
    <p>I'm a noob coder encountering a problem while parsing a csv file with the Python csv module. The problem is that my output says field values in the row are "None" for all but the first field.</p> <p>Here's the first row in the ugly csv file that I'm trying to parse (the remaining rows follow the same format): </p> <pre><code>0,213726,NORTH FORK SLATE CREEK,CAMPGROUND,North Fork Slate Creek Campground | Idaho | Public Lands Information Center | Recreation Search, http://www.publiclands.org/explore/site.php?plicstate=ID&amp;id=2268,NA,NA,NA,NA,(208)839-2211,"Nez Perce National Forest Operating Days: 305&lt;br&gt;Total Capacity: 25&lt;br&gt; 5 campsites at the confluence of Slate Creek and its North Fork. A number of trails form loops in the area. These are open to most traffic, including trail bikes.","From Slate Creek, go 8 miles east on Forest Road 354.",NA,http://www.publiclands.org/explore/reg_nat_forest.php?region=7&amp;forest_name=Nez%20Perce%20National%20Forest,NA,NA,NA,45.6,-116.1,NA,N,0,1103,2058 </code></pre> <p>Here's the code I wrote to parse the csv file (it doesn't work right!): </p> <pre><code>import csv #READER SETTINGS f_path = '/Users/foo' f_handler = open(f_path, 'rU').read().replace('\n',' ') my_fieldnames = ['col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17', 'col18', 'col19', 'col20', 'col21', 'col22', 'col23', 'col24','col25'] f_reader = csv.DictReader(f_handler, fieldnames=my_fieldnames, delimiter=',', dialect=csv.excel) #NOW I TRY TO PARSE THE CSV FILE i = 0 for row in f_reader: print "my first row was %s" % row i = i + 1 if i &gt; 0: break </code></pre> <p>And here is the output. It says all the fields except the first one are blank and I don't know why! Any suggestions would be much appreciated.</p> <pre><code>my first row was {'col14': None, 'col15': None, 'col16': None, 'col17': None, 'col10': None, 'col11': None, 'col12': None, 'col13': None, 'col18': None, 'col19': None, 'col2': None, 'col8': None, 'col9': None, 'col6': None, 'col7': None, 'col4': None, 'col5': None, 'col3': None, 'col1': '0', 'col25': None, 'col24': None, 'col21': None, 'col20': None, 'col23': None, 'col22': None} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload