【发布时间】:2014-01-24 10:56:09
【问题描述】:
我正在尝试提出一个DeprecationWarning,并根据文档中显示的示例使用代码 sn-p。 http://docs.python.org/2/library/warnings.html#warnings.warn
官方
def deprecation(message):
warnings.warn(message, DeprecationWarning, stacklevel=2)
我的
import warnings
warnings.warn("This is a warnings.", DeprecationWarning, stacklevel=2) is None # returns True
我尝试删除 stacklevel 参数,将其设置为负数、0、2 和 20000。警告总是被默默吞下。它不会发出警告或引发异常。它只是忽略该行并返回None。文档没有提到忽略的标准。发送消息,使 warnings.warn 正确发出 Userwarning.
什么可能导致这种情况,我如何得到警告以实际发出警告?
【问题讨论】:
标签: python python-2.7 warnings suppress-warnings