Skip to content Skip to sidebar Skip to footer

Is Resume() Function Available In Python 2.7?

Is there any resume() function in python. I need to apply it on my program. need proper explanation I searched a lot but didn't get it. Here is my code where I need to place the re

Solution 1:

To resume the code in case of an exception, put it inside a loop:

import time
import urllib2
from bs4 import BeautifulSoup # $ pip install beautifulsoup4

for _ in range(max_retries):
   try:
       r = urllib2.urlopen(url) 
       encoding = r.info().getparam('charset')
       html = r.read()
   except Exception as e:
       last_error = e
       time.sleep(retry_timeout)
   else:
       break
else: # all max_retries attempts failed 
   raise last_error 

soup = BeautifulSoup(html, from_encoding=encoding)
# ...

Post a Comment for "Is Resume() Function Available In Python 2.7?"