I have the following code across different files. I want to understand what is the best practice to define the global variable so that I don't have to run the function again to get the variable value. File structure as below:
00.py
def f_token():
global v_Token, v_session
auth_context = adal.AuthenticationContext("https://login.microsoftonline.com/common")
token_response = auth_context.acquire_token_with_username_password("https://xxx.xxx.dynamics.com/", username, password, client_id)
v_Token= token_response['accessToken']
return v_Token
01.py
from 00 import*
A_Token = f_token()
def f_meta():
code here
02.py
from 00 import*
A_Token = f_token()
def f_anotherfunction():
code here
03.py
from 00 import*
A_Token = f_token()
def f_function():
code here
I only want to execute f_token once and reuse the value of v_Token across file 01,02, and 03. These 3 functions are not dependant on each other. They are being executed separately. What would be the best practice for this problem?