当前位置 : 主页 > 手机开发 > ROM >

统一TXT文件格式

来源:互联网 收集:自由互联 发布时间:2021-06-10
from collections import Counter import jieba import jieba.posseg from jieba import analyse import sys #jieba.suggest_freq(‘乡村小规模学校‘, True) import re import importlib import linecache f1 = open("C:\\Users\\zyl\\Desktop\\tes
from collections import Counter import jieba import jieba.posseg from jieba import analyse import sys #jieba.suggest_freq(‘乡村小规模学校‘, True) import re import importlib import linecache
f1 = open("C:\\Users\\zyl\\Desktop\\test.txt","r",encoding=‘utf-8‘) buff = f1.readlines() f2 = open("C:\\Users\\zyl\\Desktop\\printout.txt",‘w+‘,encoding=‘utf-8‘) dataSet = [] flag = False sentence = r‘(\s)‘ for line in buff:   if line:     for i in line:       result = re.findall(sentence,i)       if result:         continue       else:         dataSet.append(i)   else:     continue   dataSet.append("\n") cache_str = "".join(dataSet) cache_list = cache_str.split("\n") for j in range(len(cache_list)):   if cache_list[j]:     f2.write(cache_list[j]+‘\n‘)   else:     continue f2.close() f3 = open("C:\\Users\\zyl\\Desktop\\printout.txt",‘r+‘,encoding=‘utf-8‘) result = f3.read() print(result)
上一篇:Jsql
下一篇:倍增求LCA
网友评论