0

I have a list with these values ['apple', 'banana', '10', 'oranges']

I want to iterate every element in the list and try to convert it into an int.

this is my code so far

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

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

Now this code works. But when I run pylint on this code I get this error

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

How should I get rid of this error?

Sashaank
  • 880
  • 2
  • 20
  • 54

1 Answers1

2

You can do except Exception:, or you can do except ValueError:

Vthechamp
  • 636
  • 1
  • 8
  • 20