全局变量管理模块 globalvar.py
def set_value(name, value):
global _global_dict
_global_dict = {}
_global_dict[name] = value
def get_value(name, defValue=None):
try:
return _global_dict[name]
except KeyError:
return defValue
set_value(‘score‘, 90)
2文件b.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import globalvar as gl
#name = gl.get_value(‘name‘)
score = gl.get_value(‘score‘)
print("%s" % (score))
原文地址:https://www.cnblogs.com/zhujunsheng/p/11392855.html
时间: 2024-10-18 15:04:07