Python-文件处理1

#写:b.txt存硬盘编码格式UTF-8
#读:python解释器默认读取文件的编码 python3默认:utf-8
#没有指定encoding参数操作系统会使用自己默认的编码(windows系统默认gbk),所以会报编码错误。所以需要指定编码为encoding="utf-8"
with open('b.txt',mode='rt',encoding="utf-8") as f:
res=f.read()
print(res)
#嘿嘿嘿
posted @ 2020-08-10 10:38  梁博客  阅读(26)  评论(0)    收藏  举报