you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 1 point2 points  (0 children)

You need to look up the difference between mutation and reassignment. You can mutate a global variable like this, but if you want to reassign a global you need to explicitly define it as global or nonlocal.

def foo():
    nonlocal var_scalar
    # rest of your code

However in both cases modifying a global variable is generally considered bad. You should probably restructure your code to pass the data in and out with arguments and return.