文件操作

1、读 r rb

f = open('好好上学',mode='r',encoding='utf-8')
content = f.read()
print(content)
f.close()

f = open('好好上学',mode='rb')
content = f.read()
print(content)
f.close()

2、只写

 

 3、追加

 

 4、读写

 

 

r+b 也是读写但是是以bytes方式

 

 r+  默认光标在最前面,因为要读

w+  因为要先清除,所以直接是读不到内容的,只有再次写入内容才能读到

a+  因为光标在最后面,所有也是读不到的

 

 

 

 

 

 

 

 

 

 

 

 








posted @ 2020-09-21 17:37  温柔他  阅读(67)  评论(0编辑  收藏  举报