python warnings模块的简单应用
2017-08-28 16:17
666 查看
最近在学习Bottle源码时发现用到了warnings相关知识,就认真学习了下,记录下来防止忘记
运行 python fxn.py
显示 this is fxn 并没有输入警告信息
添加运行参数 -W action
python -W default fxn.py
fxn.py:5: DeprecationWarning: deprecated
warnings.warn("deprecated", DeprecationWarning)
this is fxn
还可以添加error\always\ignore\等参数
默认不加-W action 应该是ignore的,如果用error做action,则不会输出this is fxn,也就是说当成错误来处理,不再向后执行了。
# -*- coding=utf-8 -*- import warnings def fxn(): warnings.warn("deprecated", DeprecationWarning) print 'this is fxn' fxn()文件为 fxn.py
运行 python fxn.py
显示 this is fxn 并没有输入警告信息
添加运行参数 -W action
python -W default fxn.py
fxn.py:5: DeprecationWarning: deprecated
warnings.warn("deprecated", DeprecationWarning)
this is fxn
还可以添加error\always\ignore\等参数
默认不加-W action 应该是ignore的,如果用error做action,则不会输出this is fxn,也就是说当成错误来处理,不再向后执行了。
相关文章推荐
- python expect模块pexpect简单应用
- python(os模块)的简单应用
- Python可视化的扩展模块matplotlib的简单应用
- Python Fabric 模块 介绍及简单应用
- python中quests模块的简单应用
- Python的logging模块的简单应用
- python字符串编码识别模块chardet简单应用
- python的paramiko模块简单应用
- python字符串编码识别模块chardet简单应用
- Python:paramiko模块简单应用
- Python可视化的扩展模块matplotlib的简单应用
- python中Tkinter模块的简单应用
- Python的os库简单应用
- Python基础知识——urllib模块在爬虫中的应用
- Python模块学习之hashlib-MD5在接口测试中的应用
- Pymongo库简单应用(Python的mongodb库)
- python的re模块应用实例
- Python 简单模块学习
- Python logger模块应用示例
- 毕业设计(十九)---文章模块管理 div弹出层的应用 简单js操作