I have a project with project with several files for one I declare one variable as None and then inside a function I update it's value.
module_1.py
import pandas as pd
df_data = None
def read_files():
global df_data
df_data=pd.read_xlsx('dummy.xlsx')
module_2.py
from module_1 import df_data
from module_1 import read_files
read_files()
print(df_data)
# This returns None
I thought that being a global variable it would update even after importing because from module_1.py file I'm updating its value. But its none.
I think its because python imports the module initially with the value None, and even if set as global it won't reload the value.
I could do a get function, but is there any other way?
What's the correct way to do this? Make a get function and return the object itself? Is there any way to refresh variables after importing them?