I am developing a code that uses a module data_module to store common data/parameters. The data/parameters are not available at the beginning but will be set in the main program. When the data/parameters are given values, they can be used by functions in other modules, which in turn, get executed in the main code.
#data_module.py
run_data = {}
predictors = []
#another_module.py
from data_module import run_data, predictors
def test():
print(run_data)
print(predictors)
If I use the following version 1 of the main code
#main1.py
from data_module import run_data, predictors
from another_module import test
run_data['full_data'] = 1
predictors = ['X1','X2']
test()
I will get
{'full_data': 1} []
So the dictionary variable run_data in the data_module.py gets updated while the list variable predictors is not.
If I want to update the list variable I have to use the extend operator
#main2.py
from data_module import run_data, predictors
from another_module import test
run_data['full_data'] = 1
predictors.extend(['X1','X2'])
test()
Please help me explain the different behaviors of dictionary and list in this example and let me know the pythonic way to modifying variables in a module for later use.