我的主模块中有一个变量,使用另一个模块进行更改,但我想将变量从主模块更改为另一个模块。我是程序员的新手,所以我实际上并不知道如何解释这些东西 - 对不起,如果我问一个愚蠢的问题。
程序的层次结构看起来有点像这样:
主
---特点
--- Pygame_handling
------功能
我使用“功能”模块更改“主要”中的变量。我这样做只是从“功能”中获取定义的变量。但是当我通过“Pygame_handling”更改变量时,它不会在“Main”模块中创建的“Features”对象中更改。
Main.py
import Features
class Simulator:
def __init__(self):
self.Features = Features.Methods()
self.variables = self.Features.dictionary
self.PyObject = Pygame_handling.Window()
Pygame_handling.py
import Features
class Window:
def __init__(self):
self.Features = Features.Methods()
dict = {"some":"dict"}
self.Features.monitor_changes(dict)
答案 0 :(得分:0)
你是如何初始化这些课程的? 通常当我需要做这样的事情时,我将其编码为:
<强> py1.py:强>
class Test(object):
def test_print(self):
print 'Hi!'
TEST = Test()
<强> py2.py:强>
from py1 import TEST
TEST.test_print()
# Adding new stuff to the TEST initialized class
TEST.new_var = 50
print TEST.new_var
#output: 50
所以现在你可以在该模块上使用初始化的类。