我有一些用 try 包装的代码,除了读取 .npz
数组
它可能会产生如下异常:
Exception ignored in: <bound method NpzFile.__del__ of <numpy.lib.npyio.NpzFile object at 0x12dd65cf8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/numpy/lib/npyio.py", line 226, in __del__
self.close()
File "/usr/local/lib/python3.6/site-packages/numpy/lib/npyio.py", line 217, in close
if self.zip is not None:
AttributeError: 'NpzFile' object has no attribute 'zip'
是否可以抑制此消息?
代码如下:
video_dir_list = get_video_dir_list(input_dir)
for video_dir in tqdm(video_dir_list):
try:
img_filepath_list = get_filepaths_by_extension(video_dir, ['*.jpg'])
for img_filepath in img_filepath_list:
data = load_npz_files(img_filepath)
except Exception as e:
BROKEN_VIDEO_LIST.append(video_dir)
最佳答案
如果你只想被动处理异常,请添加另一个 except 子句-- except AttributeError: #handle this attribute error
另外,这个异常和被忽略的异常之间有关系吗?
关于python - 抑制 numpy 异常消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57187234/