python - Python:如何存储异常值?
问题描述
我如何将异常的值存储为变量?查看较早的帖子,例如下面的帖子,这些方法在 Python3 中不起作用。不使用 pip 安装包我该怎么办?
我的目标是遍历数据,检查所有内容以查找各种内容,并保留所有错误以放入电子表格中。
较早的帖子:Python:捕获任何异常并将其放入变量中
MWE:
import sys
# one way to do this
test_val = 'stringing'
try:
assert isinstance(test_val, int), '{} is not the right dtype'.format(test_val)
except AssertionError:
the_type, the_value, the_traceback = sys.exc_info()
解决方案
except AssertionError as err:
有关解包异常内容等更多详细信息,请参阅本教程该块的底部,以“except 子句可以在异常名称后指定一个变量”开头的段落。
推荐阅读
- c# - 使用 iText 7 C# 在段落后画线
- php - 如何使用php将数据从表单输入到mysql?
- db2 - 用户定义函数的临时表
- docusignapi - 设置完成证书作为附件发送给 Docusign 签名过程中的每个接收者
- ios - ViewController 的属性为零
- javascript - ES6 静态成员被子类继承
- android - 在kotlin的api中发送不同类型的post参数
- service-worker - 服务人员检查导入脚本的字节大小差异
- php - 如何将日期从数据库更改为 dd/mm/yyyy - codeigniter 中的 php
- android - 未声明为可选的字段接受 null 作为值