with open('~/桌面/test1','a+')as f:
f.write('6883 556773833 RemyMCMXI\n'
'6880 556772838 Mindmatrix restored undeleted RemyMCMXI\n'
'6882 556771715 RemyMCMXI\n'
'6881 556770863 RemyMCMXI\n'
'6880 556673938 Liua97\n'
'6879 554350969 Epicgenius\n'
'6880 554332653 Alex\n')
f.seek(0,0)
info=[i.split() for i in f]
info_len=len(info)
for i in range(info_len):
if 'restored' in info[i]:
for j in range(i+1,info_len):
if info[i][0]==info[j][0]:
print(tmp[1] for tmp in info[i:j])
break
import os
li1=['~/PycharmProjects/'+'day'+str(i)+'.py' for i in range(1,9)]
for i in li1:
with open(i,'w') as f:
f.write(i)
def add(dirpath,suffix,newdirpath,newname):
if os.path.exits(dirpath) and os.path.exists(newname):
old_file=[i for i in os.listdir(dirpath) if i.endwith(suffix)]
for i in old_file:
with open(dirpath+i) as f1:
with open (newdirpath+newname) as f2:
for i in f1:
f2.write(i+'\n')
os.remove(i)
print('文件合并完成')
else:
print('该目录不存在')
add('~/PycharmProjects/','.py','~/PycharmProjects','all.py')
with open('~/PycharmProjects/all.py')as f:
print(f.read())