Python error "Ordinal not in range" with accents
<p>I'm scraping a table from the Internet and saving as a CSV file. There are characters with French accents in the text, resulting in a unicode error on save:</p>

<pre><code> UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-6: ordinal not in range(128)
</code></pre>

<p>I'd like to find an elegant solution for saving accented characters that I can apply to any situation. I've sometimes used the following:</p>

<pre><code> encode('ascii','ignore')
</code></pre>

<p>but it doesn't work this time, for reasons unknown. I'm also trying to replace the <code>&lt;sup&gt;</code> tags in a cell, so I'm converting it using <code>str()</code> first. </p>

<p>Here's the pertinent part of my code:</p>

<pre><code> data = [
      str(td[0]).split('&lt;sup')[0].split('&gt;')[1].split('&lt;')[0],
      td[1].getText()
 ]
 output.append(data)

 csv_file = csv.writer(open('savedFile.csv', 'w'), delimiter=',')

 for line in output:
      csv_file.writerow(line)
</code></pre>
