このコードを使用して、特定のファイル内の電子メールを検索し、それらを別のファイルに書き込みます。メールが重複しないように「in」演算子を使用しました。ただし、このコードは行の後に実行されません for line in f:
。私がここで犯した間違いを誰かが指摘できますか?
tempPath = input("Please Enter the Path of the File\n")
temp_file = open(tempPath, "r")
fileContent = temp_file.read()
temp_file.close()
pattern_normal = re.compile("[-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+.[a-zA-Z0-9_.]+")
pattern_normal_list = pattern_normal.findall(str(fileContent))
with open('emails_file.txt', 'a+') as f:
for item in pattern_normal_list:
for line in f:
if line in item:
print("duplicate")
else:
print("%s" %item)
f.write("%s" %item)
f.write('\n')