From 3533b43d9d77761c17329084065154cd3db3213e Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 29 Oct 2023 16:43:14 +0800 Subject: [PATCH] auto save --- diy.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/diy.py b/diy.py index 633645e..2df6f6a 100644 --- a/diy.py +++ b/diy.py @@ -1,13 +1,12 @@ -with open(r'c:\Users\Lenovo\Documents\lesson13-1\sales_list.txt','r',encoding='utf-8')as abcd: - a=abcd.readlines() -yyds=[] -for i in a: - data=i.split() - zbb=0 - for zxc in data[1:]: - zbb+=int(zxc) - ab=data[0]+str(zbb) - yyds.append(ab) -with open(r'c:\Users\Lenovo\Documents\lesson13-1\sales_list.txt','a',encoding='utf-8')as abcd: - abcd.writelines(yyds) +# 在diy1的基础上选一种打开方式,建议选with open() as +with open(r'C:\Users\CM\Documents\lesson13-1\sales_list.txt','r',encoding='utf-8') as file: + a=file.readlines() + #print(a) +for i in a: + b=i.split() + sum=0 + for h in b[1:]: + sum=sum+int(h) + text=b[0]+str(sum) + print(txt) \ No newline at end of file -- libgit2 0.25.0