繁体   English   中英

Python 3 中未解决的全局变量引用

[英]Unresolved Reference with Global Variables in Python 3

所以,我不确定为什么,但我在以下函数中收到来自 Pycharm 的“未解决的引用”警告。 它们的共同点是在操作中也使用了赋值变量。 我不明白为什么这行不通。 关于警告的内容有什么想法吗?

我确实通读了这个线程: PyCharm 中未解决的参考问题

它似乎与我的特殊情况不符。 认为问题不在于导入语句。 此外,我的 python 解释器似乎配置正确。

此外,不确定它是否有所不同,但函数中使用的所有变量都是全局声明的。

def OP9():
    s3 = np.tan(s3) # s3 in the tan() function is the culprit
    return s3

def OP16():
    v2 = np.heaviside(v2) # v2 in the heaviside() function is the culprit
    return v2

def OP18():
    v1 = s7 * v1 # v1 on the right of the assignment is the culprit
    return v1

您正在尝试设置一个全局,因此您需要明确说明它。

def OP9():
    global s3
    s3 = np.tan(s3) # s3 in the tan() function is the culprit
    return s3

参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM