我的主模塊中有一個變量使用另一個模塊更改,但我想從主模塊更改變量另一個模塊。我對程序設計很陌生,所以我其實不知道如何解釋這些東西 - 抱歉,如果我問一個愚蠢的問題。如何更改模塊內的模塊中的變量在模塊中......(困惑)
程序的層次看起來有點像這樣:
主要
---特點
--- 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)
你需要舉一個你的實際代碼的例子。 – BrenBarn
在你的Window類中,你調用一個函數self.Features.Methods(),但是你的Window類沒有一個Features屬性。 –
我不明白這段代碼與你的問題有什麼關係。你的兩個文件不共享任何對象。 – BrenBarn