My code goes through a number of files reading them into lists with the command:
data = np.loadtxt(myfile, unpack=True)
Some of these files are empty (I can't control that) and when that happens I get this warning printed on screen:
/usr/local/lib/python2.7/dist-packages/numpy/lib/npyio.py:795: UserWarning: loadtxt: Empty input file: "/path_to_file/file.dat"
warnings.warn('loadtxt: Empty input file: "%s"' % fname)
How can I prevent this warning from showing?
You will have to wrap the line with catch_warnings
, then call the simplefilter
method to suppress those warnings. For example:
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
data = np.loadtxt(myfile, unpack=True)
Should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With