我有一段代码,其中在执行导入的方法时某些记录发生了异常(请参见下文)。我的目标不是停止执行,而是可能会在出错时打印(以了解数据有什么问题)一些值并继续。我尝试了各种使用“try...except”的方法,但没有运气!有人可以看看并提出建议吗?提前谢谢了!
下面的代码
if student_name not in original_df_names_flat:
for org in orgs:
data = calculate(org, data)
result = imported_module.execute(data) # here's the line where exception happens
return result
else:
return data
以下解决方案解决了这个问题:
if student_name not in original_df_names_flat:
for org in orgs:
data = calculate(org, data)
try:
result = imported_module.execute(data) # here's the line where exception happens
except exception as e:
print ("exception happened", e)
pass
return data
return result
else:
return data
上面的解决方案解决了这个问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句