In the following code:
file = input("Email LIST : ") in_emails = open(file,'r',errors='ignore').read().splitlines() domain_set = set() out_emails = [] for email in in_emails: _, tmp = email.split("@", maxsplit=1) domain, _ = tmp.split(":", maxsplit=1) if domain not in domain_set: out_emails.append(email) domain_set.add(domain) print(out_emails)
I am getting the error below:
_, tmp = email.split("@", maxsplit=1) ValueError: not enough values to unpack (expected 2, got 1)
Any solution for ignoring wrong Lines ?
Advertisement
Answer
You can pave over anything that goes wrong and log it like this:
for email in in_emails: try: _, tmp = email.split("@", maxsplit=1) domain, _ = tmp.split(":", maxsplit=1) if domain not in domain_set: out_emails.append(email) domain_set.add(domain) except Exception as err: print(f"Failed to parse email '{email}'", err)