第一种:如下所示参数'w',往文件中写入类容,若是filePath不存在,则会创建新的文件

  需要注意的是,使用‘w’会将以前文件中存在的数据全部清除掉


1
fileOpen = open('filePath','w') 2 fileOpen.write('string') 3 fileOpen.close()

第二种:如下使用参数‘a’,往文件中追加类容,若是文件不存在,会创建新的文件

  使用‘a’以前文件中存在的数据不会被清除,只会在后面追加

 

1 fileOpen = open('filePath','a')
2 fileOpen.write('string')
3 fileOpen.close()

 

相关文章:

  • 2021-08-25
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2021-10-07
  • 2021-11-23
  • 2022-12-23
  • 2021-07-25
相关资源
相似解决方案