Я пытаюсь выполнить базовую проверку на наличие идентификаторов электронной почты в файле CSV.Я не знаю, почему он не проходит тщательную проверку «если».
import csv
import re
input_file = open("test_list.csv", "r").readlines()
print(len(input_file))
csv_reader = csv.reader(input_file)
line_count = 0
try:
for row in csv_reader:
line_count += 1
print('Checking ' + str(line_count) + ' of ' + str(len(input_file)))
name = {row[0]}
email = list({row[2]})
print(str(email[0]))
print('Checking contact name'+str(name))
regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$'
match = re.match(regex,str(email[0]))
if match == None :
print("Bad Email")
else:
print("Good Email")
print('')
print('')
except IndexError as error:
print('Checked all the data')
Мой CSV-файл выглядит так:
bhanu1, singh2, bha.nu@gmail.com
bhanu2, singh2, bhadoxit.com
bhanu3, singh2, bhan@esnotexit.com
Мой вывод:
3
Checking 1 of 3
bha.nu@gmail.com
Checking contact nameset(['bhanu1'])
Bad Email
Checking 2 of 3
bhadoxit.com
Checking contact nameset(['bhanu2'])
Bad Email
Checking 3 of 3
bhan@esnotexit.com
Checking contact nameset(['bhanu3'])
Bad Email