您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Python AssertionError中更改消息?

如何在Python AssertionError中更改消息?

使用e.argse.message已被弃用。

try:
    assert False, "Hello!"
except AssertionError as e:
    e.args += ('some other', 'important', 'information', 42)
    raise

这将保留原始的回溯。然后其最后一部分如下所示:

AssertionError: ('Hello!', 'some other', 'important', 'information', 42)

在Python 2.7和Python 3中均可使用。

python 2022/1/1 18:50:41 有355人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶