[英]python - accessing superclass attributes
Hi I want to achieve the following in python, however I cant figure out what to replace the line super.a = b
with: 嗨,我想在python中实现以下功能,但是我无法弄清楚用
super.a = b
代替什么行:
class Super:
def __init__(self):
self.a = 1
class Sub(Super):
def method(self, b):
super.a = b
An Sub
is a Super
, ie all instances of Sub
can be treated exactly like instances of Super
. Sub
是 Super
,即Sub
所有实例都可以像Super
实例一样对待。 In your case, that means you simply set self.a = b
. 在您的情况下,这意味着您只需设置
self.a = b
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.