python读取文件时报错‘gbk‘ codec can‘t decode byte 0x88 in position 87: illegal multibyt,怎么解决。

这个错误通常是由于使用了不正确的编码方式导致的。可以尝试以下解决方法:

1. 指定正确的编码方式进行文件读取,例如使用UTF-8编码方式读取:  

   ```
   with open("file.txt", encoding='utf-8') as f:
        content = f.read()
   ```

2. 如果无法确定文件的正确编码方式,可以尝试使用 `chardet` 库自动识别文件编码:

   ```
   import chardet

   with open('file.txt', 'rb') as f:
       content = f.read()
       result = chardet.detect(content)
       encoding = result['encoding']

   with open('file.txt', encoding=encoding) as f:
       content = f.read()
   ```

以上是两种常用的解决方法,如果仍然无法解决问题,可以尝试在读取时忽略错误并继续读取: 

```
with open('file.txt', errors='ignore') as f:
    content = f.read()
```

你可能感兴趣的:(python笔记,python)