import codecsfind_s = "控股集团董事长"alter_s = "项目公司总经理"f = codecs.open("城投-定标管理.flo","rb")f_new = open("城投-定标管理.flo.bak","wb")for line in f.readlines(): if find_s.encode('utf_16_le') in line: line = line.replace(find_s.encode('utf_16_le'),alter_s.encode('utf_16_le')) print("----------------------------------------------------------------") f_new.write(line)f.close()f_new.close()f2 = codecs.open("城投-定标管理.flo.bak","rb")for line in f2.readlines(): print(line)