首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Python 运行时捕获 Warning

Python 运行时捕获 Warning

作者头像
py3study
发布于 2020-01-10 01:15:02
发布于 2020-01-10 01:15:02
2.4K0
举报
文章被收录于专栏:python3python3
代码语言:javascript
复制
>>> import warnings
>>> 
>>> warnings.filterwarnings('error')
>>> 
>>> try:
...     warnings.warn(Warning())
... except Warning:
...     print 'Warning was raised as an exception!'
... 
Warning was raised as an exception!

参考资料:

1、http://stackoverflow.com/questions/15933741/how-do-i-catch-a-warning-in-python-like-its-an-exception-not-just-for-testing

2、https://docs.python.org/2/library/warnings.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/06 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档