import string
# Imported string to load dictionaries
d = dict.fromkeys(string.ascii_letters, 0)
ds = dict.fromkeys(string.digits, 0)
# 2 dictionaries imported, letters and numbers(digits)
f = {**d, **ds, ".":0}
# Merged both dictionaries together as well as "." as there was no specific
dictionary.
while True:
`email = input("Enter the name of the file (must be .txt file)")
file = open(str(email), "r")
for line in file:
for i in line:
if " " in line:
print(line, "Space found")
break
if "@" not in line:
print(line, "The email needs @")
emailzero = line.split("@")
if len(emailzero) < 2:
print(line, "@ and a domain symbol is needed")
continue
if emailzero[0] == "":
print(line, "You must enter a name")
if emailzero[1] == "":
print(line, "A Domain is needed")
if "." in emailzero[0]:
print(line, "Only alphabet and numbers")
for i in emailzero[0]:
if i not in f:
print(line, "The email must have a valid character before @")
break
if "." not in emailzero[1]:
print(line, "The domain needs to contain a .")
for i in emailzero[1]:
if i not in f:
print(line, "The email must not contain any invalid characters in the domain.")
break
So here's what my program does. It takes in a file of emails and checks it one by one to see if it is valid.
The problem is when I load a list with more than one email, the emails after the first all end up saying "The email must not contain any invalid characters in the domain."
Can someone tell me why this happens and how I can fix it?
Cheers,