I have the following directory
dir1\
..\main.py
..\file2.py
in main.py i have the following code
import myObj
obj1 = None
def func1():
global obj1
obj1 = myObj.myObj()
if __name__ == "__main__":
func1()
import file2.py
in file2.py:
from main.py import obj1
but obj1 is None , any idea why ?
Update: Changing the question to this : I have the following directory
dir1\
..\main.py
..\file2.py
..\file3.py
in main.py i have the following code
import file2
def func1():
file2.init_func()
if __name__ == "__main__":
func1()
in file2.py :
import myObj
obj1=None
def init_func():
global myobj
obj1= myObj.myObj()
in file3.py:
from file2 import obj1
But obj1 is None in file3,Why it is not initialized?