-2

私は2つのクラスを持っています。オブジェクト指向の方法論では、下位クラスから親属性を変更できます。Pythonでは、親の変数を他のクラスから変更するにはどうすればよいですか? 私が持っているもの

class Concurrent( threading.Thread):
    def __init__(self):
         self.rec = Rec()
         self.rec.start()
         self.parentvar = None # I have change this variable
         self.secondParentVar = [] # or use this

class Rec(Concurrent):
    def run(self):
        # from here, change variable of the parent Conccurent class variable
4

2 に答える 2

1

私はこのようなものがうまくいくと思います:

class Concurrent( threading.Thread):
    def __init__(self):
        self.rec = Rec()
        self.rec.start()
        self.parentvar = None 

class Rec(Concurrent):
    def __init__(self):
        Parent.__init__(self)
        self.parentvar = #new variable
        self.secondParentVar = [list1, list2]      
于 2013-05-20T07:04:39.667 に答える
0

おそらくあなたが望むのはこれです:

class Rec(Concurrent):
    def run(self):
        self.parentvar = "new value"
于 2013-05-20T07:21:53.713 に答える