【问题标题】:Turning warning into errors in Jupyter在 Jupyter 中将警告变成错误
【发布时间】:2021-06-02 17:11:11
【问题描述】:

我想在运行 Python 3 内核的 Jupyter Notebook 中将警告转化为错误:

from warnings import warn, simplefilter
simplefilter('error')

虽然这在从命令行使用 Python 时有效,但这会使 Jupyter 崩溃。有没有人遇到过这个问题?有人知道解决方法吗?

谢谢

【问题讨论】:

  • 我也崩溃了,你找到解决方案了吗?

标签: python python-3.x jupyter-notebook


【解决方案1】:

要将所有警告变为错误,您需要执行以下操作:

import warnings
warnings.filterwarnings('error')

更多选项请参考https://docs.python.org/3/library/warnings.html

default                      # Show all warnings (even those ignored by default)
ignore                       # Ignore all warnings
error                        # Convert all warnings to errors
error::ResourceWarning       # Treat ResourceWarning messages as errors
default::DeprecationWarning  # Show DeprecationWarning messages
ignore,default:::mymodule    # Only report warnings triggered by "mymodule"
error:::mymodule[.*]         # Convert warnings to errors in "mymodule"
                             # and any subpackages of "mymodule"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多