Read GBK Files in Python: Quick Guide
To read a file encoded in GBK in Python, you can use the codecs module for handling. Here is a simple example code:
import codecs
# 打开GBK编码的文件
with codecs.open('file.txt', 'r', 'gbk') as file:
content = file.read()
print(content)
In this example, we use the codecs.open function to open a file with a specified encoding of GBK. We then use the read() method to read the file content and print it out. This allows us to correctly read the content of a file encoded in GBK.