json数据和异常
一、文件操作的补充
如果以读的方式打开不存在的文件会报错
如果以写的方式打开不存在的文件不会报错
# open('test.txt', 'r') # 报错!
open('test.txt', 'a')
open('test.txt', 'w')
# 2.读写模式:+
# 使用方式: r+ / w+ / a+ - 读写操作
# 3.通过文件上下文打开文件
"""
文件对象 = open()
文件对象.read()/文件对象.write()
文件对象.close()
with open() as 文件对象:
文件对象.read() / 文件对象.write()
"""
with open(r'test.txt', 'w') as f:
f.write('abc')
f = open(r'test.txt', 'w')
f.write('123')
f.close