-2

I have two classes. In the object oriented methodology, I can change parent attribute from low level class. In python, how can I change variable of the parents from other class ? What I have

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

2 Answers2

2

i think something like this would work:

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]      
Serial
  • 7,925
  • 13
  • 52
  • 71
0

What you probably want is this:

class Rec(Concurrent):
    def run(self):
        self.parentvar = "new value"
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251