python - 抑制 numpy 异常消息

标签 python numpy exception

我有一些用 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/

相关文章:

Python:如何删除以某些字符结尾的行?

python-3.x - 使用 Pandas 不改变格式的平均时间

numpy - 图像从 [3,M,N] 到 [M,N,3]

Python:如何捕获异常并继续?

python - 鉴于要分配的值是非数字,如何将数据框从长更改为宽?

python - mlab 中的简单箭头 mayavi/tvtk 奇怪的行为(看起来像一个错误)

python - matplotlib set_label_position 在 3d 中没有效果?

python - 将 numpy 数组转换为另一个数组

java - JUnit 自定义运行器不工作?

java - 我想捕获 InputMismatchException 但它显示编译时错误