title: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2501: character maps to <undefined>
body: <p>I've been looking for solutions to this and haven't found any that worked. I've tried adding r in front of the filepath. I've tried changing the encoding to utf-8. Nothing seems to work.</p>
  <p>I wrote this script on a Mac and it worked fine and I'm trying to run it on Windows but it's not working.</p>
  <pre><code>fin = open(&quot;C:\\Users\\filepath\\indivsWG22.txt&quot;, &quot;rt&quot;, encoding = 'ISO-8859-1')
  fout = open(&quot;C:\\Users\\filepath\\Downloads\\out.csv&quot;, &quot;w&quot;)
  #for each line in the input file
  for line in fin:
      #read replace the string and write to output file
      #This is where I deal with all the pipes and commas
      fout.write(line.replace(',', '^').replace('|~|',',').replace('|~',',').replace('~|',','))
  #close input and output files
  fin.close()
  fout.close()
  </code></pre>
  <p>This is the full error I'm getting:</p>
  <pre><code>UnicodeDecodeError                        Traceback (most recent call last)
  &lt;ipython-input-33-22326598bb16&gt; in &lt;module&gt;
        8 fout = open(&quot;C:\\Users\\filepath\\out.csv&quot;, &quot;w&quot;)
        9 #for each line in the input file
  ---&gt; 10 for line in fin:
       11         #read replace the string and write to output file
       12     #This is where I deal with all the pipes and commas
  
  ~\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
       21 class IncrementalDecoder(codecs.IncrementalDecoder):
       22     def decode(self, input, final=False):
  ---&gt; 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
       24 
       25 class StreamWriter(Codec,codecs.StreamWriter):
  
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2501: character maps to &lt;undefined&gt;
  </code></pre>