<p>看看我下载的原始文件<a href="http://www.data.gov/download/4608/csv" rel="nofollow">here</a>,它是有效的CSV。我把你脚本的输出弄错了。在</p>
<p>因为你用了csv.DictReader每一行都被转换成一个字典,其中标题值作为键,每个行的数据作为值。我在同一个文件中运行它,看起来一切都是正确匹配的,尽管我没有检查整个过程。在</p>
<p>根据<a href="http://docs.python.org/library/csv.html" rel="nofollow">python docs</a></p>
<p><code>class csv.DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect='excel'[, *args, **kwds]]]]])</code></p>
<blockquote>
<p>Create an object which operates like a regular reader
but maps the information read into a
dict whose keys are given by the
optional fieldnames parameter. If the
fieldnames parameter is omitted, the
values in the first row of the csvfile
will be used as the fieldnames. If the
row read has more fields than the
fieldnames sequence, the remaining
data is added as a sequence keyed by
the value of restkey. If the row read
has fewer fields than the fieldnames
sequence, the remaining keys take the
value of the optional restval
parameter. Any other optional or
keyword arguments are passed to the
underlying reader instance.</p>
</blockquote>
<p>如果这不是您想要的格式,您可以尝试csv.reader它只为每一行返回一个列表,而不将其与标题相关联。在</p>
<p>要使用上面的听写器,这可能是您想要的:</p>
<pre><code>import csv
reader = csv.DictReader(open('ngl_hawaii.csv', 'rb'), delimiter=','))
for row in reader:
print row['d_first_name']
print row['d_last_name']
</code></pre>