我尝试在循环中写入一些值,但我的csv文件为空。
我有df
domain surname name patronymic
erlyvideo.ru Лапшина Юлия Юрьевна
finteca.ru Крылов Александр Александрович
我用
with open('emails.csv','w') as f1:
writer = csv.writer(f1)
for i, (sur, name, patr, dom) in enumerate(zip(df.surname.values.tolist(), df.name.values.tolist(), df.patronymic.values.tolist(), df.domain.values.tolist())):
sur = translit(sur, "ru", reversed=True).replace("'", '')
name = translit(name, "ru", reversed=True).replace("'", '')
patr = translit(patr, "ru", reversed=True).replace("'", '')
all_email = []
var0 = 'edevyataykina' + '@' + str(dom)
var1 = str(sur) + '@' + str(dom)
var2 = str(name) + '@' + str(dom)
all_email.extend([var1, var2])
if validate_email(var0, check_mx=True) == True and validate_email(var0, verify=True) == True:
res_mail = 'Catch_All'
elif validate_email(var0, check_mx=True) == False:
res_mail = 'DomainName Not Found'
elif validate_email(var0, check_mx=True) == True and validate_email(var0, verify=True) == None:
valid_email = []
for mail in all_email:
is_valid = validate_email(mail, verify=True)
time.sleep(1)
if is_valid is True:
valid_email.append(mail)
if len(valid_email) == 1:
res_mail = valid_email[0]
else:
res_mail = 'Username Not Found'
print res_mail
writer.writerow(res_mail)
为什么我可以在循环或text_file中将所有值res_mail
写入csv?