Prevent or dismiss 'empty file' warning in loadtxt
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.
One obvious possibility is to pre-check the files:
if os.fstat(myfile.fileno()).st_size:
data = np.loadtxt(myfile, unpack=True)
else:
# whatever you want to do for empty files