文件操作

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+  因为光标在最后面,所有也是读不到的

 

 

 








原文地址:https://www.cnblogs.com/jdwy24/p/13706911.html