I have a Django (so Python) program with a global variable:
g_variable = []
I use this is several functions where I also change the value:
my_function()
global g_variable
g_variable.append(some_value)
That worked great until I started calling the program multiple overlapping times - in Django that means that I loaded the webpage multiple times quickly. I expected that the global variable would only be global within each individual run, but that is not the case. The values that are appended to g_variable in one run can be seen in the next run.
To me this means that I now have to pass this variable around to all my functions:
my_function(non_g_variable)
non_g_variable.append(some_value)
return non_g_variable
called with
non_g_variable = my_function(non_g_variable)
Is that correct? Before I change all my code I just want to make sure that I haven't missed something. It will add a lot of extra lines and return calls.