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('日期','数据')

 

posted on 2018-04-10 16:42  星河赵  阅读(15148)  评论(0编辑  收藏  举报

导航