python - How to bring variables of super method into child method in Python3
问题描述
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`
解决方案
推荐阅读
- elixir - Elixir 中的流量限制
- chatbot - 在 Rasa Actions 中调用自定义函数
- r - 如何在 R Studio 中将所有整数值标记为“-1”?
- dart - 颤振设置状态 onPressed on RaisedButton
- php - POST localhost/.. 405(不允许的方法)
- reactjs - 在反应中异步加载 iframe
- angular - 如何重构从端点获取数据并再次接收数据
- python - Python:随机 StaleElementReferenceException
- python - 为什么使用 Flask 的 app.test_client() 而不是 requests.Session() 进行测试
- angular - Angular 6 和 keycloak-angular 模块:如何从服务器加载 keycloak url