try:
with open('data.txt','w') as f:
for each_line in f:
print(each_line)
except OSError as reason:
print('出错啦'+str(reason))
报错not readable
r只读,r+读写,不创建
w新建只写,w+新建读写,二者都会将文件内容清零
(以w方式打开,不能读出。w+可读写)
**w+与r+区别:
r+:可读可写,若文件不存在,报错;w+: 可读可写,若文件不存在,创建