zhaoyingjie

python 创建txt并且写入做追加

import os
def create_str_to_txt(self,date,str_data):
    """
    创建txt,并且写入
    """
    path_file_name = \'./report/action_{}.txt\'.format(date)
    if not os.path.exists(path_file_name):
        with open(path_file_name, "w") as f:
            print(f)

    with open(path_file_name, "a") as f:
        f.write(str_data)

if __name__ == \'__main__\':
create_str_to_txt(\'日期\',\'数据\')

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-03
  • 2021-11-19
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2022-01-27
  • 2022-12-23
  • 2021-11-26
  • 2022-01-09
  • 2021-09-17
相关资源
相似解决方案