python write error to file

Solutions on MaxInterview for python write error to file by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "python write error to file"
Hepsiba
13 Apr 2016
1logf = open("download.log", "w")
2for download in download_list:
3    try:
4        # code to process download here
5    except Exception as e:     # most generic exception you can catch
6        logf.write("Failed to download {0}: {1}\n".format(str(download), str(e)))
7        # optional: delete local version of failed download
8    finally:
9        # optional clean up code
10        pass
11