Configure IPython to show warnings all the time

半世苍凉 提交于 2019-12-10 17:06:49

问题


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!

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

import warnings
warnings.filterwarnings('always')

But that doesn't make any difference.


回答1:


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


来源:https://stackoverflow.com/questions/27787677/configure-ipython-to-show-warnings-all-the-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!