[Python] 纯文本查看 复制代码 from pathlib import Path
import string
from itertools import zip_longest
abc_num = dict(zip_longest(string.ascii_uppercase,['0' + str(i) for i in range(1,27)]))
def get_key(d,value):
k = [k for k,v in d.items() if v == value]
if k:
return k[0]
else:
return None
with open(Path(__file__).parent.joinpath('num.txt'), 'r',encoding='utf8') as f:
r = f.readlines()
new_r = []
for line in r:
if get_key(abc_num,line.strip()) is not None:
new_r.append(get_key(abc_num,line.strip()) + '\n')
else:
new_r.append(line)
with open(Path(__file__).parent.joinpath('num.txt'), 'w',encoding='utf8') as f:
f.writelines(new_r) |