title: Writing to a text file error - Must be str, not list
body: <p>I have been having problems with some code I am writing. Basically, when I run the code I enter an 8 digit number and it should scan the CSV file to see if the number is inside the file. If it is, the row should be written to the text file. However, when I run it and I enter a number, I get this:</p>
  <pre><code>TypeError: must be str, not list
  </code></pre>
  <p>And even when it is fixed, the output is:</p>
  <pre><code>&lt;_io.TextIOWrapper name='receipt.txt' mode='a' encoding='cp1252'&gt; 
  </code></pre>
  <p>My code is as follows:</p>
  <pre><code>import csv
  import sys
  import re
  
  addItem = &quot;&quot;
  gtinNum = &quot;&quot;
  quantity = 0
  totalPrice = 0
  
  receipt = open(&quot;receipt.txt&quot;, &quot;r+&quot;)
  f = open(&quot;ChocolateCSV.csv&quot;, &quot;rt&quot;)
  
  def scanGTIN():
      rows = re.split('\n', f.read())
  
      for index, row in enumerate(rows):
          global cells
          cells = row.split(',')
          if gtinNum in cells:
              receipt.write(cells)
  
  def gtinQuestion():
      global gtinNum
      gtinNum = input(&quot;Please enter the GTIN-8 Code of the product you would like to order:&quot;)
  
      if gtinNum.isdigit() == False or len(gtinNum) != 8:
          gtinQuestion()
      elif gtinNum.isdigit() == True and len(gtinNum) == 8:
          scanGTIN()
  
  
  gtinQuestion()
  </code></pre>