python文件操作其他

#  以读的格式打开,然后可以在后面写
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') 

转载于:https://www.cnblogs.com/dotiger/p/8277878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值