jdhao's digital space

Recent content on jdhao's digital space

马上订阅 jdhao's digital space RSS 更新: https://jdhao.github.io/index.xml

Reading and Writing Text Files on Windows

2018年12月3日 13:06

If you are using Python 3 on Windows, you may have seen a Unicode decoding error when opening files in UTF-8 format:

UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xaf in position 5: illegal multibyte sequence

If you read the same file on Linux or macOS, you will find that this file can be opened without any error. Why is there a difference? It has something to do with the default encoding Python chooses to use on different platforms.