python - 在脚本中执行脚本,但继续进行错误并将其保存到文件

标签 python python-2.7 error-handling try-except execfile

如果我要使用以下代码:

try: 
    execfile("script.py")
except ## unsure what exception goes here...
    continue:
try: 
    execfile("other.py")
except ## unsure what exception goes here...
    continue:

如何捕获script.py中的所有错误,将其保存到文件中,然后继续执行下一个调用的脚本

任何人有任何想法或线索吗?

最佳答案

errors = open('errors.txt', 'w')
try: 
    execfile("script.py")
except Exception as e:
    errors.write(e)
try: 
    execfile("other.py")
except Exception as e:
     errors.write(e)
errors.close()

关于python - 在脚本中执行脚本,但继续进行错误并将其保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18198574/

相关文章:

python - 将多个变量断言为同一类型

python - 使用 python 将另一列添加到 CSV 文件

Python re : why does [, -_] 匹配 "="?

python-2.7 - python-boilerpipe 挂起多处理

error-handling - 如何从事件网格事件触发的 Azure 函数正确返回状态/错误代码

python - 使用 python 检查 Beautiful Soup 4 中的子项标签

python - 在 Python 中使用单个正则表达式在输入字符串中搜索出现的整数和字符

python - QSqlQuery插入数据库不起作用

python - 我不知道如何在python范围内输入日期

model-view-controller - ZF2 : Listen for an MVC Exception, 然后重定向