验证错误:从外部范围重新定义外部名称 [英] Validation Error: Redefined outer name from outer scope

查看:41
本文介绍了验证错误:从外部范围重新定义外部名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我是否明白,但我收到了来自 pyLint 的验证错误说:

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)

代码是这样的:

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?

推荐答案

称您为其他变量:

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

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

您可以为传入的变量使用任何名称,不必将它们称为 ab.它不会以任何方式影响您的代码,因为变量被传递到函数中,如果您在代码中的多个位置有 a 和 b 并且您决定将 a 更改为 var_a 但忘记在一两个地方更改它,那么您将获得与您期望的不同的输出.

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.

这篇关于验证错误:从外部范围重新定义外部名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆