junfanbl
junfanbl

Reputation: 461

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

Upvotes: 0

Views: 1327

Answers (1)

Boomer
Boomer

Reputation: 479

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

Upvotes: 1

Related Questions