title: Python csv: preserve headers when writing to file
body: <p>I wrote a simple function that acts depending on the number of rows of the CSV the user is supplying, by either adding or removing columns:</p>
  
  <pre><code>def sanExt(ifpath, ofpath):
      with open(ifpath, "rb") as fin, open(ofpath, "wb") as fout:
          csvin = csv.reader(fin)
          csvout = csv.writer(fout, delimiter=",")
          fline = csvin.next()
          if len(fline) == 33:
              for row in csvin:
                  row.insert(10, "NULL")
                  csvout.writerow(row)
              print "AG"
          elif len(fline) == 35:
              print "AI"
          elif len(fline) == 36:
              print "AJ"
          else:
              print "Unknown"
  </code></pre>
  
  <p>I've stopped at the first <code>if</code> statement, just to make sure my code works. The column is properly added in this case, but the headers are missing.</p>
  
  <p>How do I make sure every row is written to the file, not just <code>[1:len(rows)]</code>?</p>
  
  <p>Is my method the proper pythonic way to do the desired job?</p>