简体   繁体   中英

Unresolved Reference with Global Variables in Python 3

So, I'm not sure why, but I'm getting an "Unresolved Reference" warning from Pycharm in the following functions. The one thing they have in common is that assignment variable is also used in the operation. I don't see why this wouldn't work. Any thoughts on what the warning is about?

I did read through this thread: Unresolved reference issue in PyCharm

It doesn't appear to match my particular case. Seeing as the issue is not with import statements. Also, my python interpreter appears to be configured properly.

Also, not sure if it makes a difference, but all variables used in the functions are declared globally.

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

You're trying to set a global so you need to be explicit about it.

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

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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