I have three files file_a.py, file_b.py and func.py:
In func.py, I have:
import datetime
def a_simple_function():
print("hello from simple function")
return datetime.datetime.now()
global_variable = a_simple_function()
In file_b.py, I have:
from func import global_variable # second time import
def func_in_b():
print("print from file b:", global_variable)
In file_a.py, I have:
from func import global_variable # first time import
from file_b import func_in_b
print("print from file a:", global_variable)
func_in_b()
When run from file_a, I see the following output:
hello from simple function
print from file a: 2019-06-17 14:14:42.293202
print from file b: 2019-06-17 14:14:42.293202
Why does hello from simple function appear once instead of twice? I think I've imported it twice in different files.
Basically I am trying to set a global_variable used both in file_a.py and file_b.py, the global_variable is generated by a function in file func.py.