建议单独创建一个文件
global_var.py
def _init():
global _global_dict
_global_dict = {}
def set_value(name, value):
_global_dict[name] = value
def get_value(name, defValue=None):
try:
return _global_dict[name]
except KeyError:
return defValue
def get_all():
return _global_dict
从哪里使用全局变量 ,就引用这个文件
configDict = gl_var.get_value("configDict")
print("修改之前",configDict)
configDict.pop("threshold")
print("删除后", configDict)
b = "threshold"
configDict[b] = a
gl_var.set_value("configDict", configDict)
configDict = gl_var.get_value("configDict")
print("修改之后", configDict)
这是一个不错 配置文件的文章https://www.cnblogs.com/liuyl-2017/p/7833986.html