Home > Net >  Pause in "for i in range" with in python
Pause in "for i in range" with in python

Time:10-26

How can I make a pause in a "for i in range" loop, for example after 100 calls?

I have this part of the code:

with open(r'url\url.txt', encoding='utf8') as f:
    for i in range(total_urls):

Now I want to make a big pause after 100 calls.

All I find is to do time.sleep() or set a random pause between calls, but this is not what I need. I already have a 10 second pause between calls, but I need to make a longer pause after 100 calls.

CodePudding user response:

Like this?

with open(r'url\url.txt', encoding='utf8') as f:
    for i in range(total_urls):
        if i > 0 and i % 100 == 0:
            time.sleep(100)
  • Related