Importing modules: __main__ vs import as module
问题 To preface, I think I may have figured out how to get this code working (based on Changing module variables after import), but my question is really about why the following behavior occurs so I can understand what to not do in the future. I have three files. The first is mod1.py: # mod1.py import mod2 var1A = None def func1A(): global var1 var1 = 'A' mod2.func2() def func1B(): global var1 print var1 if __name__ == '__main__': func1A() Next I have mod2.py: # mod2.py import mod1 def func2():