Q:

Why don't global variables defined by imported functions change?

I have a function in a file:
global_value = 100    #defualt
def function(new_value):
    global global_value
    print(global_value,new_value)
    global_value = new_value

function() takes in a value,compares it to global_value and then sets the global_value to new_value. 
I am not using this function within the file, rather importing it.
(file2:)
from file import *
value = input("enter value")
function(value)
print(global_value)

The function works correctly however at the end global_value is shown to be equal to 100 (it's defualt value), not the input.
What can I do to make global_value change in file2 as well?
thanks.

A:

Global variables in Python aren't really global; they are scoped to a particular module.
After you execute from file import *, you have two variables; file.global_variable, which is the one that file.function updates, and a new global_variable in the current module which is initialized using the original value of file.global_variable, but is never updated by function.
Each function contains a reference to the global scope in which the function was defined. In Python 2 it's file.function.func_globals; in Python 3 its tmp.function.__globals__. That is the scope in which any of its "global" variables are looked up, not the scope in which the function is called.
Add a plain import file to your second file, then run print(global_variable, file.global_variable) to see the difference.

