title: What's wrong with this python program working on .csv?
body: <p>I have a text file with a list of strings.</p>
  
  <p>I want to search a .csv file for rows that begin with those strings and put them in a new .csv file. </p>
  
  <p>In this instance, the text file is called 'output.txt', the original .csv is 'input.csv' and the new .csv file is 'corrected.csv'.</p>
  
  <p>The code:</p>
  
  <pre><code>import csv
  
  file = open('output.txt')
  while 1:
      line = file.readline()
      writer = csv.writer(open('corrected.csv','wb'), dialect = 'excel')
      for row in csv.reader('input.csv'):
          if not row[0].startswith(line):
              writer.writerow(row)
      writer.close()
      if not line:
          break
      pass
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Python32\Sample Program\csvParser.py", line 9, in &lt;module&gt;
  writer.writerow(row)
  TypeError: 'str' does not support the buffer interface`
  </code></pre>
  
  <p>New error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Python32\Sample Program\csvParser.py", line 12, in &lt;module&gt;
  for row in reader:
  _csv.Error: line contains NULL byte
  </code></pre>
  
  <p>Problem  was that the CSV file was saved with tabs instead of commas, new issue now is the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python32\Sample Program\csvParser.py", line 13, in &lt;module&gt;
      if row[0] not in lines:
  IndexError: list index out of range
  </code></pre>
  
  <p>The CSV file has 500+ entries of data... does this make a difference?</p>