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+: 可读可写,若文件不存在,创建

相关文章:

  • 2021-08-13
  • 2021-09-09
  • 2022-12-23
  • 2021-11-25
  • 2021-07-28
  • 2021-07-20
  • 2022-02-19
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2021-11-19
  • 2022-12-23
  • 2021-09-02
  • 2021-08-02
  • 2021-06-13
  • 2021-10-12
相关资源
相似解决方案