# 以读的格式打开,然后可以在后面写
f4= open('hello2', 'r+',encoding= 'utf-8') # 这种模式下面 最好先读取一下 否则可能会出问题
print (f4.readline())
print (f4.readline())
f4.write('nihao a ')
f4.write('可以写了')
f4.write('可以写了')
f4.write('可以写了')
print (f4.tell())
f4.close()
# 写读
f4 = open('hello2','w+',encoding='utf-8')# 以写的格式打开,写的时候,可以读
f4 = open('hello2','a+',encoding='utf-8')#追加读写
# 文件的修改
f5 = open('dream it possible','r', encoding= 'utf-8')
f6 = open('dream it possible2','w', encoding= 'utf-8')
for line in f :
if 'Then It’s worth fighting for' in line:
line = line.replace('Then It’s worth fighting for', '呵呵')
f6.writelines(line )
#以二进制格式写文件,应该是传输一些视频等文件的时候,可以使用
# rb ab 是以二进制文件格式读取 追加文件
f7 = open('text.txt','wb',encoding = 'utf-8')