📜  python 将错误写入文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:14.154000             🧑  作者: Mango

代码示例1
logf = open("download.log", "w")
for download in download_list:
    try:
        # code to process download here
    except Exception as e:     # most generic exception you can catch
        logf.write("Failed to download {0}: {1}\n".format(str(download), str(e)))
        # optional: delete local version of failed download
    finally:
        # optional clean up code
        pass