私はPythonを学ぼうとしています。クラス間で共有変数が残っています。メインのクラスからの変数へのアクセス
私はこのような変数設定クラスがあります:私は私のメインからnew_games
にアクセスしたい
class CheckStuff(threading.Thread):
def __init__(self, debug):
threading.Thread.__init__(self)
self.debug = debug
self.newGames = False
def get_new_games(self):
return self.newGames
def set_new_games(self, new_games):
self.newGames = new_games
def run(self):
# DO STUFF #
# ... #
self.set_new_games(True)
return
を、私はこのように試してみました:
if __name__ == "__main__":
debug = True
t1 = cs.CheckStuff(debug)
t1.start()
t1.join()
print(cs.CheckStuff(debug).get_new_games())
exit()
しかし、これは常にFalse
を返します。どこが間違っていますか?任意のヒントが評価されました
質問がありますか? "cs"とは何ですか? –
これはトップからインポートされたものです: 'import CheckStuff as cs ' – PrimuS
ありがとう、次回この単純な行を追加するか、これを避けるために" cs "を削除してください。最良の問題は、コードを自分のIDEにコピーしてコピーし、未定義のメソッドや変数を検索せずに実行して、それらを削除できるかどうかです。 –