简体   繁体   English

python - 访问超类属性

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM