After opening a file through open in python, The UnicodeDecodeError exception is thrown when the file contains the Chinese fd. readline. It can be basically determined that the encoding of the read file is a problem. Because the Read File uses the C ++ code written by VS, and the default storage encoding of vs is gb2312. It works when converting file encoding to UTF-8. The fundamental solution is to unify the code written by VS into the code of the UTF-8, but this part of the code is not maintained by me, and the code is still being added, other developers through VS quickly establish C ++ class, asking them to use the advanced save option to save as UTF-8 seems to have the difficulty of writing, can only temporarily solve this problem through themselves. Prototype of the open function: Specify the encoding of the open file by specifying the encoding parameter. The default value of encoding is the UTF-8, which can be obtained through fd. encoding. To automatically obtain the file encoding format, the chardet module must support it. The solution is to use UTF-8 to read files by default. When a UnicodeDecodeError error occurs, with open (fn, "r") as fd blocks will automatically disable fd, you can simply re-open the file using gbk encoding in bytes T.