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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM