May 19, 2019 2:08 PM
文件的读写,由内置模块open 进行操作和实现
- 文本文件读操作
with open('data.txt') as file_read:
txt = file_read.read()
print(txt.strip())
- 文本文件的追加
#文件的追加
with open('data.txt','a') as file_append:
file_append.write('\nNice to meet you!')
- 文件的重写
#文件的重写
with open('data.txt','w') as file_write:
file_write.write('clear and rewrite')
- 如果是二进制文件,需要采用==‘rb’,‘wb’,‘ab’==的方式打开