Python - 我可以知道是否发生打印

问题描述:

我写了一个简单的python脚本。
在脚本中我使用

I wrote a simple python script. During the script i'm using

os.system ("diff file1 file2")

来检查两个文本文件是否相似。
我知道文件是类似的,如果没有打印出来。
如果没有打印,我想打印出一些
到命令行,像>文件是类似的。

to check if two text files are similar or not. I know the files are similar if nothing is being printed out. In case nothing is being printed, i'd like to print out something to the command line like "> the file are similar".

任何想法?

>>> import filecmp
>>> filecmp.cmp('file1.txt', 'file1.txt')
True

如果 True ,那么只是打印消息,两者都是类似的

filecmp - 逐个字节有效的比较是

if True then just print message like both are similar
filecmp- A byte by byte efficient comparison it is