使用报错
blob = TextBlob(Path('draft.txt').read_text())
Traceback (most recent call last):
File “D:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py”, line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in
blob = TextBlob(Path(‘draft.txt’).read_text())
File “D:\anaconda3\lib\pathlib.py”, line 1267, in read_text
return f.read()
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x93 in position 2348: illegal multibyte sequence
原因是记事本使用的编码格式和默认编码格式不匹配,因此需要额外指定
blob = TextBlob(Path('draft.txt').read_text(encoding='utf-8'))