Reputation: 1109
I would like to import a module, use a function of that module and get a warning message every time the event that triggers the warning happens, not just the first time.
For example if I do (within ipython):
import scipy as sp
import matplotlib.pyplot as plt
x = sp.linspace(0,10)
plt.plot(x,1j*x)
I get the following warning:
/usr/lib/python2.7/dist-packages/numpy/core/numeric.py:320: ComplexWarning: Casting complex values to real discards the imaginary part return array(a, dtype, copy=False, order=order)
however, if I do
plt.plot(x,1j*x)
again, I don't get a warning message. As I said above, I would like to receive a warning message every time, not just the first time.
Thanks in advance.
Upvotes: 0
Views: 114
Reputation: 1109
I figured it out. Add
import warnings
warnings.filterwarnings('always')
before calling
plt.plot(x, 1j*x)
Upvotes: 1