I build from classes some kind of tree. Each instance of a class (except the root) has an ancestor, and a variable containing an instance of a class must, when a function is called, like go_upper (which is a class method), change the value to an ancestor. I explain badly, sorry. Maybe it will be clearer if you look at the sample code.
This is how it looks like:
class Test: def __init__(self, parent): self.parent = parent def go_upper(self): self = self.parent class _RootTest(Test): def __init__(self): pass first = _RootTest() second = Test(first) second.go_upper() # Переменной second должно присвоиться first
How can you implement something like that?
self
in the scope of thego_upper
method. - mkkik