Search code examples
pythonpython-3.xflake8

flake8: ignore F841 unused variable for variable name _ex


I have the following code and expecting flake8 not to raise any error as the variable name _ex starts with a underscore. But flake8 still gives me F841 local variable '_ex' is assigned to but never used error. How can I get rid of the error?

try:
    1/0
except ZeroDivisionError as _ex:
    print("zero division error")

Solution

  • I just dropped the variable and it worked

    try:
        1/0
    except ZeroDivisionError:
        print("zero division error")