Validation Error: Redefined outer name from outer scope

妖精的绣舞 提交于 2019-12-10 18:07:06

问题


Not sure I get this but I got a validation error from pyLint saying:

Redefining name 'a' from outer scope (line 443) (redefined-outer-name)
Redefining name 'b' from outer scope (line 444) (redefined-outer-name)

The code is like this:

a = 98  # line 443
b = 90  # line 444

def prodNr(a, b):
    """Definiera prodNr"""
    return a * b

result = prodNr(a, b)

ANSWER = result

Could anyone please give me a clue on how to get rid of the validation error?


回答1:


Call you variables something else:

def prodNr(a, b):
    """
    Definiera prodNr
    """

    return a * b
i = 98
j = 90
result = prodNr(i, j)

You can use any name for the variables you pass in they don't have to be called a and b. It does not affect your code either way as the variables are passed into the function, it would be a problem if you had a and b in multiple places in your code and you decided to change a to var_a but forgot to change it in one or two places then you would get different output to what you would expect.



来源:https://stackoverflow.com/questions/28843079/validation-error-redefined-outer-name-from-outer-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!