2

I am implementing a subclass Child where an overwritten method some_method calls the parent method first. I want to use variable a from the parent method in the child method. Is there a neat way to do this without having to modify the code of Parent?

class Parent:
    def __init__(self):
        pass

    def some_method(self):
        a = 0


class Child(Parent):
    def __init__(self):
        super().__init__()

    def some_method(self):
        super().some_method()
        b = a - 1   # Here I would like to keep using `a`
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • No, you can't. You can only get the return value of the parent method. If you can modify the code of the parent class, you have all kinds of options. But you say that that's not possible, so I'm sorry but the answer is just a plain old "No". – mypetlion Sep 24 '18 at 22:18
  • Possible duplicate of [How can I get the values of the locals of a function after it has been executed?](https://stackoverflow.com/questions/4214936/how-can-i-get-the-values-of-the-locals-of-a-function-after-it-has-been-executed) – Artemij Rodionov Sep 24 '18 at 22:31

0 Answers0