2 回答
TA贡献1946条经验 获得超4个赞
import re
s = '''File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\datetime_range.vue
content: 'default': '至'
Line: 24
Time: 2018-03-26 08:46:13
-------------------------------------------------------------------------------
File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vue
content: <div><span class="branch-num">{{checkBranchNum}}</span><lang>个</lang><
Line: 6
Time: 2018-03-26 08:46:13
-------------------------------------------------------------------------------
File:D:\svn\aCenter\windows\dap\store\vdidc\web\vue-ui\src\components\piece.vue
content: <div class="branch"><lang>分支</lang></div>
Line: 7
Time: 2018-03-26 0'''
p2 = re.compile(r'[^\u4e00-\u9fa5]')
result = {i: i for i in " ".join(p2.split(s)).strip().split()}
# {'个': '个', '至': '至', '分支': '分支'}
优雅的写在本地,比如你的文件是1.txt
import re
p2 = re.compile(r'[^\u4e00-\u9fa5]')
with open('1.txt', 'r') as r:
result = {i: i for i in ' '.join(p2.split(''.join(r.readlines()))).strip().split()}
print(result) # {'个': '个', '分支': '分支', '至': '至'}
添加回答
举报