title: csvreader.fieldnames not recognized as an attribute of a csv reader object in python
body: <p>I am trying to extract the header of a CSV file in Python by using the CSV module.</p>
  <p>The CSV file is quite flat, and looks something like:</p>
  <blockquote>
  <p><strong>This, That, The Other</strong></p>
  <p>1, 2, 3</p>
  </blockquote>
  <p>I am doing the following:</p>
  <ol>
  <li>Read in the CSV file and make the reader object</li>
  <li>push the reader's iterator to the next line to force it to access the first line at least once (from the csv module documentation: &quot;If not passed as a parameter when creating the object, this attribute is initialized upon first access or when the first record is read from the file.&quot;)</li>
  <li>assigning the <code>.fieldnames</code> attribute to a variable and print it</li>
  </ol>
  <p>here is a snippet of code to illustrate:</p>
  <pre><code>datafile = open(fname, &quot;rb&quot;)
  reader = csv.reader(datafile) #use csv module to parse in the header
  reader.next() # read next line so header will be accessed
  rfd_header = reader.fieldnames
  
  print &quot;header:\n&quot;
  print rfd_header
  </code></pre>
  <p>This results in an error:</p>
  <blockquote>
  <p>AttributeError: '_csv.reader' object has no attribute 'fieldnames'</p>
  </blockquote>
  <p>Which sounds like the <code>.fieldnames</code> attribute isn't there, but is in the documentation of Python 2.6.6 (same version of python I am using)</p>
  <p>I would appreciate any insight into this mystery. If there is an alternative method to extract the header that would be awesome too!</p>
  <p>Thanks.</p>