Python 当中from ... import ... ,在原模块当中改变值并不改变引入后的符号值的问题
https://stackoverflow.com/questions/3536620/how-to-change-a-module-variable-from-another-module
from config import *
print(HAHA)
config.init_configs()
print(HAHA)
最好使用local variable
import config
config.init_configs()
HAHA = config.modify_HAHA()
print(HAHA)
# ...在local变量域使用HAHA
# all of the configurations are stored explicitly in this globally visible dict
# global dict can preserve the variable as the code is alive, which can save time for re-initing and reloading
# However, we should avoid directly accessing the value inside a module, i.e. `from ... import some_preserved_alive_global_value`
config_dict = {}
def get_configs(specific_yaml_path="exp.yaml"):
# renaming for explicity
global config_dict
# modify the global dict
# return the var, use it in another scope/context
return config_dict
本博文本意在于记录个人的思考与经验,部分博文采用英语写作,可能影响可读性,请见谅
本文来自博客园,作者:ZXYFrank,转载请注明原文链接:https://www.cnblogs.com/zxyfrank/p/15928340.html