Python多线程映射错误的数据
我正在制作一个电子邮件过滤器来过滤非工作域,由于某种原因,它正在映射域以及电子邮件列表。 预期的行为将使每个线程接收电子邮件并尝试与所有域与所有域匹配,如果它们与任何一个不匹配 当前行为映射域列表,因此对于第一封电子邮件,它仅检查第一个域,第二个域,第二个域,依次在
domains = open("domains_test.txt", 'r')
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
print(to_filter)
return(unfiltered_email)
with open("test.txt", "r") as websites, open("filtered.txt", "a") as filtered:
with ThreadPoolExecutor() as executor:
for filtered_email in executor.map(filter_list, websites):
filtered.write(filtered_email)```
from concurrent.futures import ThreadPoolExecutor
domains = open("domains_test.txt", 'r')
emails = open("test.txt", "r")
filtered = open("filtered.txt", "a")
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
filtered.write(unfiltered_email)
for email in emails:
filter_list(email)
编辑中:我删除了多线程,但问题仍然存在
domains = open("domains_test.txt", 'r')
emails = open("test.txt", "r")
filtered = open("filtered.txt", "a")
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
filtered.write(unfiltered_email)
for email in emails:
filter_list(email)
I was making an Email filter to filter out non-work domains and for some reason, it's mapping the domains as well as the email list.
expected behaviour would be for each thread to take an email and try to match it against all domains and if it doesn't match any of them it returns it to the main function to append it to the filtered file
current behaviour it maps the domains list so for the first email it checks only the first domain, the second domain for the second and so on
domains = open("domains_test.txt", 'r')
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
print(to_filter)
return(unfiltered_email)
with open("test.txt", "r") as websites, open("filtered.txt", "a") as filtered:
with ThreadPoolExecutor() as executor:
for filtered_email in executor.map(filter_list, websites):
filtered.write(filtered_email)```
from concurrent.futures import ThreadPoolExecutor
domains = open("domains_test.txt", 'r')
emails = open("test.txt", "r")
filtered = open("filtered.txt", "a")
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
filtered.write(unfiltered_email)
for email in emails:
filter_list(email)
edit: I removed multithreading yet the issue persists
domains = open("domains_test.txt", 'r')
emails = open("test.txt", "r")
filtered = open("filtered.txt", "a")
def filter_list(unfiltered_email):
to_filter = 0
for domain in domains:
print("checking " + domain + " for " + unfiltered_email)
matcher = unfiltered_email.lower().find(domain.lower())
if matcher != -1:
to_filter = 1
if to_filter == 0:
filtered.write(unfiltered_email)
for email in emails:
filter_list(email)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论