我觉得你好想想多了。即然全文替换。哪么你只需要遍历你的dict
a_dict = {'apple':'1','tree':'2','123456':'3'}
input_file = open(r'd:\test_body.txt',"r").read()();
for key,value in a_dict.items():
input_file=input_file.replace(key,value);
这样子不行吗?
我觉得你好想想多了。即然全文替换。哪么你只需要遍历你的dict
a_dict = {'apple':'1','tree':'2','123456':'3'}
input_file = open(r'd:\test_body.txt',"r").read()();
for key,value in a_dict.items():
input_file=input_file.replace(key,value);
这样子不行吗?