如何在 if 问题中制作这个 python 命令:
import filecmp
filecmp.cmp('old_index.html', 'new_index.html')
这些命令的答案是"真"或"假"。这样我就可以在文件相同或不同时执行某些操作。
感谢您的帮助
你可以简单地在if
语句中使用它,就像这样
if filecmp.cmp('old_index.html', 'new_index.html'):
# Do whatever you want if the files are the same
print("Both the files are same")
else:
# Do whatever you want if the files are NOT the same
print("No, the files are NOT the same")
if filecmp.cmp('old.html','new.html')==False:
#do something like-
print 'files are not equal'
#same code for True value