python - 验证错误 : Redefined outer name from outer scope

标签 python python-3.x scope pylint

不确定我是否明白这一点,但我从 pyLint 收到验证错误说:

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

谁能告诉我如何消除验证错误?

最佳答案

称你为其他变量:

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

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

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

关于python - 验证错误 : Redefined outer name from outer scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28843079/

相关文章:

python 子进程在 systemctl 启动时找不到 shell 命令

python - Pycharm - 编辑安装包

Django collectstatic 没有错误。但是静态文件不会在网站上同时加载调试 true 和 false。 S3 上的文件

perl - 后备打开文件 Perl

python - 属性错误: 'float' object has no attribute 'texty'

python - 重命名 pandas Dataframe 列及其下的数据

python - Boost Python Numpy - 未定义的初始化引用

python - 如何在 Python 中使用 Bokeh 查看 Holoviews 的选项

c++ - 使用运算符重载时,难以在命名空间内分离类的 header /源

java - 访问私有(private)变量