我有一个小脚本:
#!/usr/bin/python3.2
#takes the bad_emails out of full_emails and leaves us with good_emails
#This is a manually generated list of bad emails (bounce backs)
bad_list = []
with open("bad_emails.txt","r") as bad:
for line in bad.readlines():
bad_list.append(line)
#this is a list of ALL email addresses output by AcyMailing
full_emails = []
with open("full_emails.txt","r") as full:
for email in full.readlines():
if email in bad_list:
pass
else:
full_emails.append(email)
#this is a final list containing only the email addresses with want
good_list = []
with open("good_emails","w") as good:
for email in full_emails:
good.write(email)
简而言之,我要做的是:从我们在 Joomla 中名为 AcyMailing 的邮件程序中获取电子邮件地址列表并将其导出。它具有以下格式:“abc@abc.com”“def@def.com”“etc@etc.etc”
虽然我上面的脚本有效(它摆脱了“坏电子邮件”,只留下了“好电子邮件”,但我还没有找到一种方法让每封电子邮件都像 AcyMailing (Joomla) 使用的那样被引号包围。我已经看到很多人使用正则表达式来完成这样的任务。这是在 python 中执行此操作的唯一方法吗?