title: python - Converting a non-ascii character to a specific character
body: <hr>
  
  <p>Hello everyone and thanks for your time !</p>
  
  <p>I have iso-8859-1 html files as input, with html entities in place of non-ascii characters, which is neat. Except for only one character : œ (00C9 unicode codepoint, just in case it doesnt display). I want to convert it to "oe" to get rid of it.</p>
  
  <p>I already tried
      iconv -f iso-8859-1 -t ascii//translit</p>
  
  <p>but it rips off the problematic character and doesnt put anything in its place.</p>
  
  <p>I work with python 2.7 and I tried several things around decode, encode, codecs, but I'm not going anywhere.
  Here is my code at this point :</p>
  
  <pre><code>i=0
  for file in os.listdir(dir_in):
  i+=1
  file=codecs.open(dir_in+file,"r","iso-8859-1")
  out=codecs.open(dir_out+str(i)+".html","w","utf-8")
      for line in file:
              #at this point the type of line is "unicode"
      line=line.decode("iso-8859-1",errors="replace")
              out.write(line)
  file.close
  out.close
  </code></pre>
  
  <p>(I have trouble making the indent display correctly but I assure you this part is fine)
  I get an "ascii codec cant encode character u\x9c" error. I'm not sure if I'm using decode appropriately.</p>
  
  <p>I also tried :</p>
  
  <pre><code>line=unicode(line)
  </code></pre>
  
  <p>which gets rid of the character without a replacement (which is what its supposed to do I guess)</p>
  
  <pre><code>line=unicode(line, errors="replace")
  </code></pre>
  
  <p>which gives me "TypeError : decoding Unicode is not supported"
  I suppose those two didnt work because I'm not supposed to give to "unicode" an already unicode thing.</p>
  
  <p>If you got a simple method to do it in bash or in perl I'm interested too, but I cant use python 3 as it's not supported by the server which will have to run the thing.</p>
  
  <p>Thanks a lot !</p>