隐藏ipython中的所有警告 [英] Hide all warnings in ipython

查看:176
本文介绍了隐藏ipython中的所有警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个ipython会话的截屏视频,并且为了避免混淆观众,我想禁用来自不同包的 warnings.warn 调用所发出的所有警告。有没有办法配置ipythonrc文件来自动禁用所有这些警告?

I need to produce a screencast of an ipython session, and to avoid confusing viewers, I want to disable all warnings emitted by warnings.warn calls from different packages. Is there a way to configure the ipythonrc file to automatically disable all such warnings?

推荐答案

我最终想通了。地点:

import warnings
warnings.filterwarnings('ignore')

〜/ .ipython / profile_default / startup / disable-warnings.py 中。我要离开这个问题并回答记录,以防其他人遇到同样的问题。

inside ~/.ipython/profile_default/startup/disable-warnings.py. I'm leaving this question and answer for the record in case anyone else comes across the same issue.

通常一次看到警告是有用的。这可以通过以下方式设置:

Quite often it is useful to see a warning once. This can be set by:

warnings.filterwarnings(action='once')

这篇关于隐藏ipython中的所有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆