python io open()写入中文乱码问题:
with open("test.txt", "wt") as out_file
out_file.write("该文本写入到文件中")
with open("test.txt", "rt") as in_file:
text = in_file.read()
print(text) # ���ı�д�뵽�ļ���
解决写入中文乱码问题,在open()中添加encoding = " utf-8 "
with open("test.txt", "wt", encoding= "utf-8") as out_file:
out_file.write("该文本写入到文件中")
with open("test.txt", "rt", encoding="utf-8") as in_file:
text = in_file.read()
print(text) # 该文本写入到文件中