这是我的模块:
test1.py
我看到虽然我只从
regions=["a","b","c"]
print "from test1 module"
test2.py
from test1 import regions
print "from test2 module", regions
运行test2.py文件
python test2.py
from test1 module
from test2 module ['a', 'b', 'c']
我看到虽然我只从
test1.py
导入regions
列表,但是打印语句print
仍然被调用。我没有写import test1.py
让一切都被执行。
1)为什么会执行test1.py
文件中的所有内容(当然不包括__name__==__main__
)?
2)如何只从test1模块
中导入regions list
而不执行所有其他语句?
我不知道这就是导入工作的方式,并且由于此问题而努力解决了3天的错误。