Python多线程映射错误的数据

发布于 2025-02-12 10:59:00 字数 1859 浏览 0 评论 0原文

我正在制作一个电子邮件过滤器来过滤非工作域,由于某种原因,它正在映射域以及电子邮件列表。 预期的行为将使每个线程接收电子邮件并尝试与所有域与所有域匹配,如果它们与任何一个不匹配 当前行为映射域列表,因此对于第一封电子邮件,它仅检查第一个域,第二个域,第二个域,依次在


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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文