我有以下功能。该程序查看每个文件并将所有 4 个文件中出现的行打印到一个新文件中。我试过file1.close()
了,但我收到关于关闭集合的错误?我想我可以使用一个with
语句,但不知道该怎么做,我对编程很陌生。
def secretome():
file1 = set(line.strip() for line in open(path + "goodlistSigP.txt"))
file2 = set(line.strip() for line in open(path + "tmhmmGoodlist.txt"))
file3 = set(line.strip() for line in open(path + "targetpGoodlist.txt"))
file4 = set(line.strip() for line in open(path + "wolfPsortGoodlist.txt"))
newfile = open(path + "secretome_pass.txt", "w")
for line in file1 & file2 & file3 & file4:
if line:
newfile.write(line + '\n')
newfile.close()