WITH
global index_add_counter
You do not define, just declare that you want to say that there is a global variable index_add_counter elsewhere , and not create a global name index_add_counter . As you do not call, Python tells you that it cannot import this name. Therefore, you just need to remove the global and initialize your variable:
index_add_counter = 0
Now you can import it with:
from app import index_add_counter
Design:
global index_add_counter
used inside module definitions to force the interpreter to look for this name in the module area, and not in the definition:
index_add_counter = 0 def test(): global index_add_counter
source share