python两个文件的对比
#encoding=utf-8 class SyncPagemaptoDB(object): def loadOldmap(self,oldpage,newpage,new_version): map_reduce = {} map_reduce_new = {} #加载上次的版本 for line in open(oldpage): page, model, r_path, version, entry = line.strip().split('\t') map_reduce["%s#%s#%s" % (page, model,r_path)] = entry #加载新的版本 for line2 in open(newpage): page,model,r_path,version, entry = line2.strip().split('\t') key = "%s#%s#%s" % (page, model,r_path) map_reduce_new[key] = {} map_reduce_new[key]["page"] = page map_reduce_new[key]["model"] = model map_reduce_new[key]["r_path"] = r_path map_reduce_new[key]["version"] = new_version map_reduce_new[key]["entry"] = map_reduce.get(key,'') values = [] for key,v in map_reduce_new.iteritems(): sql = "('%s','%s','%s','%s','%s')" % (v['page'],v['model'],v['r_path'],v['version'],v['entry']) values.append(sql) content = ",".join(values) print content def main(): Pagemap = SyncPagemaptoDB() #上一个版本,新的版本,新版本version Pagemap.loadOldmap('map_7_3_0','map_7_3_1','7.3.1'); if __name__ == "__main__": main()