我应该使用什么类型的异常来避免 No exception type(s) specified

What type of exception should I use to avoid No exception type(s) specified

我有一个 list 具有这些值 ['apple', 'banana', '10', 'oranges']

我想遍历列表中的每个元素并尝试将其转换为 int

这是我到目前为止的代码

lst = ['apple', 'banana', '10', 'oranges']

for i in lst:
    try:
        int_ele = int(i)
        print(int_ele)
    except:
        continue

现在这段代码可以工作了。但是当我 运行 pylint 在这段代码上我得到这个错误

W0702: No exception type(s) specified (bare-except)

我应该如何摆脱这个错误?

你可以except Exception:,或者你可以except ValueError: