如何让我的全局变量在导入其他模块期间可用?
How to get my global variables to be available during imports of other modules?
在 python 3 中,我有一个全局字典,mydict
看起来像:
global mydict #this is line 1
mydict = {'property1':'value',...
在这一行之后,我导入了一个模块:
from my_module import my_mod
在导入上放置一个断点显示我的全局作为全局的一部分存在。
在my_module
(导入)的第一行放置断点表明我的变量不是全局变量的一部分。
我希望这个全局变量在导入时在导入的文件中可用。我该怎么做?
我会创建一个新模块
mydict.py
mydict = {'property1':'value',...
importing.py
global mydict #this is line 1
from mydict import mydict
from my_module import my_mod
my_module.py
from mydict import mydict
我想其他方法会更难。
在 python 3 中,我有一个全局字典,mydict
看起来像:
global mydict #this is line 1
mydict = {'property1':'value',...
在这一行之后,我导入了一个模块:
from my_module import my_mod
在导入上放置一个断点显示我的全局作为全局的一部分存在。
在my_module
(导入)的第一行放置断点表明我的变量不是全局变量的一部分。
我希望这个全局变量在导入时在导入的文件中可用。我该怎么做?
我会创建一个新模块
mydict.py
mydict = {'property1':'value',...
importing.py
global mydict #this is line 1
from mydict import mydict
from my_module import my_mod
my_module.py
from mydict import mydict
我想其他方法会更难。