如何解决使用 super 更改子类 python 中的属性值
我有这门课
class Config:
def __init__(self,config_file):
self.conf = {'expected conf': {
't1': ['host','user','password','database','project_name'],'t2': ['url','password']
},'optional conf': {
't1': ['a1','a2'],'t2': ['c1']
}}
try:
self._get()
except NoSectionError:
raise SystemExit()
def _get(self):
for key,value in self.conf['expected conf'].items():
for arg in value:
try:
self._parse(key,arg)
except NoOptionError:
log.error(f"expected argument {arg} is missed! \n expected conf: {self.conf['expected conf']}")
raise SystemExit()
我会将这个类继承给另一个类,但只更改 conf 属性。
我试试这个:
class TpConfig(Config):
def __init__(self,config_file):
super(TpConfig,self).__init__(config_file)
self.conf = {'new': 'value'}
但是因为在改变属性之前执行了_get函数所以会产生错误
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。