配置IPython以始终显示警告 [英] Configure IPython to show warnings all the time

查看:90
本文介绍了配置IPython以始终显示警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次执行在IPython shell中引发警告的操作时,我看到了.但是后来我没有.例如,

The first time I do something that raises a warning in the IPython shell, I see it. But subsequent times I do not. For example,

In [1]: import numpy as np
In [2]: np.uint8(250) * np.uint8(2)
/Users/me/anaconda/envs/py33/bin/ipython:1: RuntimeWarning: overflow encountered in ubyte_scalars
#!/bin/bash /Users/me/anaconda/envs/py33/bin/python.app
Out[2]: 244

In [3]: np.uint8(250) * np.uint8(2)
Out[3]: 244       # No warning!

如何将IPython配置为始终显示警告?我尝试过:

How do I configure IPython to always show warnings? I've tried:

import warnings
warnings.filterwarnings('always')

但这没什么区别.

推荐答案

我认为这是相对解决的 IPython小组最近.由于warnings的设计决策有些不正常,因此效果不佳.在普通的Python中使用always就足够了,现在,如果我在IPython干线中执行相同的操作:

I think this was addressed relatively recently by the IPython team. It wasn't playing well with warnings because of a somewhat unusual design decision. Turing on always suffices for me in plain Python, and now if I do the same thing in IPython trunk:

In [1]: import warnings

In [2]: warnings.filterwarnings('always')

In [3]: import numpy as np

In [4]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
  #!/home/dsm/sys/root/bin/python3.4
Out[4]: 244

In [5]: np.uint8(250) * np.uint8(2)
/home/dsm/sys/root/bin/ipython3.4:1: RuntimeWarning: overflow encountered in ubyte_scalars
  #!/home/dsm/sys/root/bin/python3.4
Out[5]: 244

这篇关于配置IPython以始终显示警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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