python文件中的语句,按顺序执行,执行import时,原文件会入栈,等import文件执行完成后,才会出栈执行。 load/const.py --- import os DB_ADDRESS = os.getenv("DB_ADDRESS", "10.63.132.xxx:27017") load/main.py --- import os from load.const import DB_ADDRESS if __name__ == "__main__": os.environ["DB_ADDRESS"] = "xx" print(DB_ADDRESS) > python load/main.py 输出: 10.63.132.xxx:27017
原文:https://www.cnblogs.com/wenlin-gk/p/10919228.html