I have a script that I would like to remove the pre-allocation of variables and move it into another script (function). For example, I would like to take the following portion of code from 'script1.py':
var1 = {}
var2 = {}
var3 = {}
And put this into 'function1.py':
def preallocate_vars():
var1 = {}
var2 = {}
var3 = {}
I can then call the function 'preallocate_vars' via 'function1.py' from 'script1.py' and then continue on my business. Something like:
script1.py
from function1 import preallocate_vars
..
(do some work)
..
preallocate_vars()
..
(do some more work)
..
var1[0] = data1
var2[0] = data2
var3[0] = data3
...
However, when I try something like this, I get an error that 'var1 is not defined' in my script1.py. How can this be fixed?