- 读取
- with open('filename') as file_object: 获得文件操作实例file_object , with自动关闭文件
- 方法
- read() 读取全部
- for line in file_object: 逐行读取
- readlines() 包含文件各行内容的列表
- 写入
- with open(filename, 'w') as file_object:
- 文件操作模式:
- 'r' 读取模式, 默认模式
- ’w' 写入模式, 会清空文件
- ‘a' 附加模式
- ’r+' 读写模式
- wirte()
- json存储数据
- json.dump()
- json.load()
python简明笔记 - 文件操作
最新推荐文章于 2024-05-30 11:43:13 发布