我的源代码为:
# 第一步:打开文件 file = open(r"E:softwareTestPythonfilea.txt","r") # 第二步:读取文件内容 txt = file.read() print(txt) # 第三步:关闭文件 file.close()
原因:
- python中默认的编码方式为gbk,而Windows的默认编码方式为UTF-8,所以设置python编码方式为UTF-8就行啦
# 第一步:打开文件 file = open(r"E:softwareTestPythonfilea.txt","r",encoding='UTF-8') # 第二步:读取文件内容 txt = file.read() print(txt) # 第三步:关闭文件 file.close()
完事儿!



