# 文件打开模式b模式 #强调 # 1.与t模式类似不能单独使用,必须是rb,wb,ab # 2.b模式下读写都是以bytes为单位的 # 3.b模式下一定不能指定encoding参数 # rb模式 # with open('字符编码.png','rb') as f: # data=f.read() # print(data) # print(type(data)) # with open('a.txt','rb') as f: # data=f.read() # #decode 把文件以什么字符编码打开 # print(data.decode('utf-8'))#bytes--->unicode # print(type(data)) # wb模式 # with open('b.txt','wb') as f: # msg = '你好,小马哥' # encode 把文件以什么字符编码写入 # f.write(msg.encode('utf-8')) # t模式只能操作文本文件 # b模式可有操作任何文件,以二进制(bytes)显示 #ab模式 # with open('a.txt','ab') as f: # f.write('helio'.encode('utf-8')) # with open('a.txt','r',encoding='utf-8') as f1,open('b.txt','a',encoding='utf-8') as f2: # for line in f1: # f2.write(line) # #decode 把文件以什么字符编码打开 # print(data.decode('utf-8'))#bytes--->unicode # print(type(data))
python 文件打开b模式
猜你喜欢
转载自blog.csdn.net/qq_42721964/article/details/81195225
今日推荐
周排行