title: python Convert Encoding:LookupError: unknown encoding: ansi
body: <p>Because my cdv file is encoded as <code>utf-8</code>, opening it with Excel will cause distortion, and when I then convert it to the standard <code>ANSI</code> encoding, I get this error:</p>
  <p>code:</p>
  <pre><code>import chardet
  
  def convertEncoding(from_encode,to_encode,old_filepath,target_file):
      f1=file(old_filepath)
      content2=[]
      while True:
          line=f1.readline()
          content2.append(line.decode(from_encode).encode(to_encode))
          if len(line) ==0:
              break
  
      f1.close()
      f2=file(target_file,'w')
      f2.writelines(content2)
      f2.close()
  
  
  
  convertFile = open('4321.csv','r')
  data = convertFile.read()
  print chardet.detect(data)
  if chardet.detect(data)['encoding']=='utf-8':
      convertFile.close()
      convertEncoding(chardet.detect(data)['encoding'], &quot;ansi&quot;, &quot;4321.csv&quot;, &quot;4321_bak.csv&quot;)
  </code></pre>
  <p>error:</p>
  <pre><code>{'confidence': 0.99, 'encoding': 'utf-8'}
  Traceback (most recent call last):
    File &quot;/Users/allenlee/Desktop/convert/convert.py&quot;, line 24, in &lt;module&gt;
      convertEncoding(chardet.detect(data)['encoding'], &quot;ansi&quot;, &quot;4321.csv&quot;, &quot;4321_bak.csv&quot;)
    File &quot;/Users/allenlee/Desktop/convert/convert.py&quot;, line 8, in convertEncoding
      content2.append(line.decode(from_encode).encode(to_encode))
  LookupError: unknown encoding: ansi
  [Finished in 0.1s with exit code 1]
  </code></pre>
  <p>Thanks for your concern.</p>