title,content,dic=[],[],{'a':0} withopen(MyClippingsPath,'r') as f: line = f.readline().strip('\xef\xbb\xbf') while line : index=dic.get(line,-1) if index == -1: index = dic[line]=len(title) title.append(line) content.append('')
f.readline() #time f.readline() #blank line whileTrue: #content start line = f.readline().strip() if line == '==========' : break#content end content[index]+=line content[index]+='\n'*3 line = f.readline() #next clipping title
withopen(OutPutPath,'w') as f: for i , titleName inenumerate(title): f.write(titleName+'\n\n') f.write(content[dic[titleName]]) f.write('\n\n==========\n\n') print'ok'