可以使用Python中的文件操作和字符串查找功能来实现。具体步骤如下:
file1 = open('file1.txt', 'r')
file2 = open('file2.txt', 'r')
content1 = file1.read()
content2 = file2.read()
if 'string' in content1:
print(2)
else:
print(1)
file1.close()
file2.close()
完整代码如下:
file1 = open('file1.txt', 'r')
file2 = open('file2.txt', 'r')
content1 = file1.read()
content2 = file2.read()
if 'string' in content1:
print(2)
else:
print(1)
file1.close()
file2.close()
上一篇:比较两个文件,然后替换值