我試圖在 2 個不同的文件中找到公共行,并試圖在一個新的文本文件中列出它們。我在下面寫了這個,但它沒有找到公地,只寫我在 arg2 中提供的任何文件。請幫我排除故障。#!/usr/bin/pythonimport sysdef find_common_lines(arg1, arg2, arg3): fh1 = open(arg1, 'r+') fh2 = open(arg2, 'r+') with open(arg3, 'w+') as f: for line in fh1 and fh2: if line: f.write(line) fh1.close() fh2.close()number_of_arguments = len(sys.argv) - 1if number_of_arguments < 3: print("ERROR:\tThe script is called with less than 3 arguments, but it needs 3!") print("Usage:\tfind_common_lines.py <file1> <file2> <output_filepath>")else: arg1 = sys.argv[1] arg2 = sys.argv[2] arg3 = sys.argv[3] find_common_lines(arg1, arg2, arg3)所以,基本上我想讓這個腳本做的是:文件AAABBBCDDEGGC文件B123AABDDE345GHYGJK文件 CAABDDE謝謝?。?!
在 2 個不同文件中查找公共行
人到中年有點(diǎn)甜
2021-08-17 18:56:33