python - 访问超类属性

python  - 访问超类属性

问题描述:

您好我想在python中实现以下功能,但我无法弄清楚用 super.a = b 替换行:

Hi I want to achieve the following in python, however I cant figure out what to replace the line super.a = b with:

class Super:
  def __init__(self):
    self.a = 1

class Sub(Super):
  def method(self, b):
    super.a = b


Sub 超级,即 Sub 的所有实例都可以被视为与 Super 的实例完全相同。在您的情况下,这意味着您只需设置 self.a = b

An Sub is a Super, i.e. all instances of Sub can be treated exactly like instances of Super. In your case, that means you simply set self.a = b.