Python3文本文件/txt文件追加

        代码(三行)

student_score_file = open('student_data.txt', mode='a+')
student_score_file.write('李四\t59\n')
student_score_file.close()

        效果(执行一次)

        效果(执行两次)

        结论:在模式'a+'的情况下,write内容到文件中是追加。

        备注:如果是希望重写,则运行下面的代码

student_score_file = open('student_data.txt', mode='w+')
student_score_file.write('李四\t59\n')
student_score_file.close()


版权声明:本文为qq_36158230原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。