How can Python be used to write line breaks to a csv as '\n'?
<p>I need to redefine the following code so that any line breaks in the row data (that would show up as a blank line) show as <code>'\n'</code> in the written file.</p>

<p>However, <code>'\n'</code> needs to be written after each row to show up as a blank line.</p>

<p>Each row apparently needs to be encoded as 'utf-8' to avoid errors. </p>

<pre><code>with open('csvfile.csv', 'w') as csvOutput:
    testData = csv.writer(csvOutput, delimiter='|', escapechar=' ', quoting=csv.QUOTE_NONE)

    for row in data:
        newRow = [row[x].encode('utf-8') for x in xrange(len(row))]
        testData.writerow(newRow)
        testData.writerow(['\n'])
</code></pre>