How to compare the contents of two files in python

Problem Description:

In actual development, it is often encountered that it is necessary to judge whether the contents of two files are equal. How to judge whether the contents of files in different formats are consistent? For example, to judge two .json files, or two .pt files, or two .txt files

problem solved

import filecmp
file1 = path
file2 = path2
if filecmp.cmp(file1, file2): #file1和file2是待比较的两个文件的路径地址
    print("两个文件内容完全相同")
else:
    print("两个文件内容不完全相同")

Guess you like

Origin blog.csdn.net/weixin_41862755/article/details/129770832