1
#conf.py
def init():
global mylist
mylist=[]
#change.py
import conf
def change():
if __name__ == "__main__":
print('Direct')
conf.mylist.append('Directly executed')
print(conf.mylist)
else:
conf.mylist.append('It was imported')
#exec.py
import conf
import change
conf.init()
change.change()
print (conf.mylist)
當運行exec.py結果是我所期待的,但運行change.py時,直接我沒有得到任何輸出(無直接,無conf.mylist
)Python的進口VS直接執行