我的代码经过一些文件,用命令将它们读入列表:
data = np.loadtxt(myfile, unpack=True)
Run Code Online (Sandbox Code Playgroud)
其中一些文件是空的(我无法控制),当发生这种情况时,我会在屏幕上显示此警告:
/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)
Run Code Online (Sandbox Code Playgroud)
如何防止此警告显示?
MSa*_*lmo 15
您将必须包装该行catch_warnings,然后调用该simplefilter方法来禁止这些警告.例如:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
data = np.loadtxt(myfile, unpack=True)
Run Code Online (Sandbox Code Playgroud)
应该这样做.
| 归档时间: |
|
| 查看次数: |
5999 次 |
| 最近记录: |