python警告设置,配置IPython以始终显示警告

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.

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值