我有两节课。在面向对象的方法中,我可以从低级类更改父属性。在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
答案 0 :(得分: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]
答案 1 :(得分:0)
你可能想要的是:
class Rec(Concurrent):
def run(self):
self.parentvar = "new value"