-1

python 3 cannot read my file. The file is a Bengali word database. I wrote the following code:

x = open('c:\\BengaliWordList_112.txt').read()

The code is showing me the following error:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-12-0b3d4d6e7768> in <module>
----> 1 x = open('c:\\BengaliWordList_112.txt').read()

~\Anaconda3\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 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 0x8d in position 28: character maps to <undefined>
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153

1 Answers1

1

Try this instead:

x = open('c:\\BengaliWordList_112.txt', encoding='utf-8').read()
JasonLauHK
  • 41
  • 4