From e35c24dcb3506c3cfd4c19c19038ba4388b36a2f Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 24 Oct 2021 08:28:39 +0800 Subject: [PATCH] save project --- diy.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 diy.py diff --git a/diy.py b/diy.py new file mode 100644 index 0000000..3e7b936 --- /dev/null +++ b/diy.py @@ -0,0 +1,12 @@ +# 写入同学们的捐赠明细:'小兰:12本'、'小丽:11本'、'李文:9本'、'张伟:16本' +#f = open(r"C:\Users\Administrator\Desktop\test.txt",'a',encoding='utf-8') +#如果在一次程序的运行中,连续调用write函数写入数据,则可以追加写入文件 +#如果两次或者多次运行程序写入数据,那么后一次运行程序时的写入会把前一次运行程序时写入的数据,覆盖掉。 +#将模式改为a,即append的首字母,使得程序以追加的方式将数据写入文件,这样,多次运行程序都不会覆盖写入的数据 +#f.write("小强:10本\n") +#f.write("李明:15本\n") +#f.close() + +with open(r'C:\Users\Administrator\Desktop\test.txt','a',encoding='utf-8') as f: + f.append("小强:10本\n") + f.append("李明:15本\n") \ No newline at end of file -- libgit2 0.25.0