Python 3无法读取我的.txt文件。我如何解决它?
python 3无法读取我的文件。该文件是一个孟加拉语单词数据库。我编写了以下代码:Python 3无法读取我的.txt文件。我如何解决它?,python,string,utf-8,character-encoding,Python,String,Utf 8,Character Encoding,python 3无法读取我的文件。该文件是一个孟加拉语单词数据库。我编写了以下代码: x = open('c:\\BengaliWordList_112.txt').read() 代码向我显示以下错误: UnicodeDecodeError Traceback (most recent call last) <ipython-input-12-0b3d4d6e7768> in <module> ----> 1 x =
x = open('c:\\BengaliWordList_112.txt').read()
代码向我显示以下错误:
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>
请尝试以下方法:
x=open'c:\\BengaliWordList_112.txt',编码='utf-8'。读取
是的,有帮助。非常感谢。这很有效。谢谢