查询一个文件里面的内容是否出现在另一个文件里

import os
import sys


class Diff:
    def __init__(self):
        pass

    def run(self, url_file, template_file):
        f_template = open(template_file, 'r')
        f_tem = f_template.readlines()

        f_url = open(url_file, 'r')
        url_lines = f_url.readlines()
        flag = False

        for url_line in url_lines:
            flag = False
            if url_line is None or url_line == "":
                continue
            else:
                ss = url_line.split(".")
                if len(ss) < 2:
                    continue
                for tem_line in f_tem:
                    if url_line.find(tem_line.strip(' \r\n\t')) >= 0:
                        flag = True
                        continue

                if flag == False:
                        print "%s::not exist" % url_line
        f_template.close()
        f_url.close()


if __name__ == "__main__":
    differ = Diff()

    differ.run("topic_url", "one_out")

你可能感兴趣的:(查询一个文件里面的内容是否出现在另一个文件里)