# f=open(r'b.txt','w',encoding='utf-8')
# # print(f.writable())
# f.write('111
')
# f.write('1111
')
# f.writelines(['111
','222
'])
# f.close()
# a 模式 文件不存在则创建,存在则打开文件,光标直接移到末尾开始追加写
# f=open(r'b.txt','a',encoding='utf-8')
# # print(f.writable())
# f.write('345
')
# f.write('234
')
# f.write('235
')
# f.writelines(['qwe
','wer
'])
# f.close()
# f=open(r'b.txt','r',encoding='utf-8')
# # print(f.read())
# # print(f.readlines())
# print(f.readline())
# print(f.readline(),end='')
# print(f.readline(),end='')
# print(f.readline(),end='')
# f.close()
# with open(r'b.txt','r',encoding='utf-8')as f:
# while True:
# print(f.readline())
# print(f.readline())
# print(f.readline())
# print(f.readline())
# print(f.readline())
# print(f.readline())
# print(f.readline())
# with open(r'b.txt', 'r', encoding='utf-8')as f:
# while True:
# line=f.readline()
# if len(line) == 0:
# break
# print(line)
# with open(r'b.txt', 'r', encoding='utf-8')as f:
# for line in f:
# print(line)
# bytes模式
# with open('timg.jfif','r', encoding='utf-8')as f:
# pass
# f.read()
# with open('timg.jfif', 'rb')as f: # rb 不能指定字符编码
# f.read()
# print(f) # <_io.BufferedReader name='timg.jfif'>
# with open(r'b.txt', 'rb', encoding='utf-8')as f:
# line=f.read()
# print(line) # 报错 ValueError: binary mode doesn't take an encoding argument
# with open(r'b.txt', 'rb')as f:
# line=f.read()
# # print(line) # b'111
qwe
wer
'
# print(line.decode('utf-8')) # 111 qwe wer
# with open(r'b.txt', 'rb')as f:
# line=f.read()
# # print(line) # b'111
qwe
wer
xe8x8bxb9xe6x9ex9c
'
# print(line.decode('utf-8')) # 111 qwe wer 苹果
# with open(r'b.txt', 'wb')as f:
# f.write('RNG,Who is the winner!'.encode('utf-8'))
# with open(r'b.txt', 'ab')as f:
# f.write('OBOS,Who is the winner!'.encode('utf-8'))
# cp
# 源大小的问题
# 文件打开模式的问题
# with open('rfile','rb')as read_f,
# open('wfile','wb')as write_f:
# for line in read_f:
# write_f.write(line)
# write_f.flush() # 写一行刷一行 (了解)
# import sys # 导入模块,把别人写好的模块拿过来用
# print(sys.argv) # 专门接受你执行脚本时给他传的参数
# 脚本文件就是一个文件代表一个程序
# 文件修改
# with open(r'b.txt', 'r', encoding='utf-8')as f:
# data=f.read()
# # print(data)
# # print(data.replace('Who','Rambo')) # 字符串不可以更改
# data=data.replace('Who','Rambo') # 在内存里更改
# print(data)
# import os 文件过大就撑死了
# with open(r'b.txt', 'r', encoding='utf-8')as f1,
# open(r'.b.txt.swap','w',encoding='utf-8')as f2:
# data = f1.read()
# data = data.replace('Who', 'Rambo')
# f1.write(data)
# os.remove('b.txt')
# os.rename('.b.txt.swap','b,txt')
# with open(r'b.txt', 'r', encoding='utf-8')as read_f,
# # open(r'.b.txt.swap','w',encoding='utf-8')as wf:
# # fou line in read_f:
# # if 'Who' in line:
# # line=line.replace('Who', 'Rambo')
# # wf.write(line)
# # os.remove('b.txt')
# # os.rename('.b.txt.swap','b,txt')