title: Writing with Python's built-in .csv module
body: <p>[Please note that this is a different question from the already answered <a href="https://stackoverflow.com/questions/1019200/how-to-replace-a-column-using-pythons-built-in-csv-writer-module">How to replace a column using Python’s built-in .csv writer module?</a>]</p>
  
  <p>I need to do a find and replace (specific to one column of URLs) in a huge Excel .csv file. Since I'm in the beginning stages of trying to teach myself a scripting language, I figured I'd try to implement the solution in python.</p>
  
  <p>I'm having trouble when I try to write back to a .csv file after making a change to the contents of an entry. I've read the <a href="http://docs.python.org/3.0/library/csv.html" rel="nofollow noreferrer">official csv module documentation</a> about how to use the writer, but there isn't an example that covers this case. Specifically, I am trying to get the read, replace, and write operations accomplished in one loop. However, one cannot use the same 'row' reference in both the for loop's argument and as the parameter for writer.writerow(). So, once I've made the change in the for loop, how should I write back to the file?</p>
  
  <p><strong>edit:</strong> I implemented the suggestions from S. Lott and Jimmy, still the same result</p>
  
  <p><strong>edit #2:</strong> I added the "rb" and "wb" to the open() functions, per S. Lott's suggestion</p>
  
  <pre><code>import csv
  
  #filename = 'C:/Documents and Settings/username/My Documents/PALTemplateData.xls'
  
  csvfile = open("PALTemplateData.csv","rb")
  csvout = open("PALTemplateDataOUT.csv","wb")
  reader = csv.reader(csvfile)
  writer = csv.writer(csvout)
  
  changed = 0;
  
  for row in reader:
      row[-1] = row[-1].replace('/?', '?')
      writer.writerow(row)                  #this is the line that's causing issues
      changed=changed+1
  
  print('Total URLs changed:', changed)
  </code></pre>
  
  <p><strong>edit:</strong> For your reference, this is the <strong>new</strong> full traceback from the interpreter:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Documents and Settings\g41092\My Documents\palScript.py", line 13, in &lt;module&gt;
      for row in reader:
  _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
  </code></pre>