我如何使用 python 3.6.1 进行比较 2 directories/folders,用于文件到文件(XML)的差异

How can i use python 3.6.1 for compare 2 directories/folders, for file-to-file(XML) difference in it

我想在 *.log 文件中记录差异,以便在 2 个目录或文件夹之间逐行比较每个文件到文件。

开始求差

k=0
for i in dirs1:
    for j in dirs2:
        if i==j:
            with open(os.path.join(path1,os.path.basename(i)), 'r') as f1:
                with open(os.path.join(path2,os.path.basename(j)), 'r') as f2:
                    k+=1
                    print('TC'+str(k)+ ' started...')
                    print(os.path.join(path1,os.path.basename(i)), '\t',os.path.join(path2,os.path.basename(j)))
                    out_file.flush()
                    name1=os.path.basename(i)
                    name2=os.path.basename(j)
                    if name1==name2:
                        diff = difflib.ndiff(f1.readlines(), f2.readlines())
                        out_file.flush()
                        testPassed=None
                        #print lines with difference
                        for line in diff:
                            if line.startswith('-') and not(line.startswith('- <ID') or line.startswith('-Created        :') or  line.startswith('-Name=') or line.startswith('- <Information') or line.startswith('- ,,Date:') or line.startswith('- ,,,')):
                                testPassed=True
                                out_file.write(line)
                                out_file.flush()
                            elif line.startswith('+') and not(line.startswith('+ <ID') or line.startswith('+Created        :') or line.startswith('+Name=') or line.startswith('+ <Information') or line.startswith('+ ,,Date:') or line.startswith('+ ,,,')):
                                testPassed=True
                                out_file.write(line)
                                out_file.flush()
                        if not testPassed ==True:
                            print('\tTC'+str(k)+' Passed for: %s\n' %i)
                        else:
                            print('\t\t***TC'+str(k)+' Failed for: %s ***\n' %i)