title: Python CSV not writing data to file
body: <p>I am running into a wall with this.  I am new to writing CSV files with python and have been reading lots of different posts on the topic, but now I ran into a wall with this and could use a little help.</p>
  
  <pre><code>import csv
  #headers from the read.csv file that I wan't to parse and write to the new file.
  headers = ['header1', 'header5', 'header6', 'header7']
  #open the write.csv file to write the data to
  with open("write.csv", 'wb') as csvWriter:
      writer = csv.writer(csvWriter)
  #open the main data file that I want to parse data out of and write to write.csv
  with open('reading.csv') as csvfile:
      readCSV = csv.reader(csvfile, delimiter=',' )
      csvList = list(readCSV)
      #finds where the position of the data I want to pull out and write to write.csv
      itemCode = csvList[0].index(headers[0])
      vendorName = csvList[0].index(headers[1])
      supplierID = csvList[0].index(headers[2])
      supplierItemCode = csvList[0].index(headers[3])
      for row in readCSV:
          writer.writerow([row[itemCode], row[vendorName], row[supplierID], row[supplierItemCode]])
      csvWriter.close()
  </code></pre>
  
  <p>---UPDATE---
  I made the changes suggested and tried commenting out the following part of the code &amp; changing 'wb' to 'w' and the program worked.  However, I don't understand why, and how do I set this up so that I can list the header I want to pull out?</p>
  
  <pre><code>csvList = list(readCSV)
  itemCode = csvList[0].index(headers[0])
  vendorName = csvList[0].index(headers[1])
  supplierID = csvList[0].index(headers[2])
  supplierItemCode = csvList[0].index(headers[3])
  </code></pre>
  
  <p>Here is my updated code:</p>
  
  <pre><code> headers = ['header1', 'header5', 'header6', 'header7']
      #open the write.csv file to write the data to
      with open("write.csv", 'wb') as csvWriter, open('reading.csv') as csvfile:
          writer = csv.writer(csvWriter)
          readCSV = csv.reader(csvfile, delimiter=',' )
          """csvList = list(readCSV)
          #finds where the position of the data I want to pull out and write to write.csv
          itemCode = csvList[0].index(headers[0])
          vendorName = csvList[0].index(headers[1])
          supplierID = csvList[0].index(headers[2])
          supplierItemCode = csvList[0].index(headers[3])"""
          for row in readCSV:
              writer.writerow([row[0], row[27], row[28], row[29]])
  </code></pre>