簡體   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