Replacing text in a file with csv file
<p>I want to replace text in a text file with names that are in a csv file. For example, I have a text file that says:</p>

<pre><code>Dear [name here],
Hello . . .. etc etc
</code></pre>

<p>And a csv file that has a 2 columns with the first name in the first and the last name in the second: </p>

<pre><code>Joe Smith
Rachel Cool
</code></pre>

<p>How would I be able to read in the CSV file, and replace each name with the text [name here] in the file? I have this so far after opening the text and csv file and putting the first and last names in the variable names:</p>

<pre><code>for row in f.readlines():
    names = row.split(",")[0], row.split(",")[1]
</code></pre>

<p>And after that I tried doing something like this, but it isnt working:</p>

<pre><code>for row in textfile.readlines():
   print row.replace("[name here]", names)
</code></pre>

<p>And after running it, a TypeError: expected a string or other character buffer error. Assuming because the variable names isnt defined in the second for loop. </p>

<p>But how would I be able to read both files and replace just the [name here] in the text file?</p>