Python-如何在具有范围的另一个循环中运行循环?

时间:2018-10-20 01:00:06

标签: python loops for-loop

我不知道我的头衔是否真的涵盖了我要完成的任务。我有一个电子邮件地址列表,我只希望每天发送约50个电子邮件。因此,我使以下脚本均无法正常工作:

email_list = ['first@email.com','second@email.com','third@email.com','fourth@email.com','fifth@email.com']
for num in range(0, 2):
    for email in email_list:
        print(email)
    time.sleep(2)

email_list = ['first@email.com','second@email.com','third@email.com','fourth@email.com','fifth@email.com']
    for email in email_list:
        for num in range(0, 2):
            print(email)
        time.sleep(2)

所以我想做的是运行脚本50次,然后等待特定时间段,然后运行下一个周期。

1 个答案:

答案 0 :(得分:1)

email_list =['first@email.com','second@email.com','third@email.com','fourth@email.com','fifth@email.com']
send = 0
for email in email_list:
    print(email)
    send += 1
    if send % 50 == 0:
        time.sleep(2)

这将每打印50封邮件等待2秒