def convert(dictionary我的类中有一个辅助函数 ( )__init__来协助配置设置。定义如下:
class Configuration:
def __init__(self, config_file=None, config=None):
if config_file is not None:
with open(config_file) as in_file:
self._config = yaml.load(in_file, Loader=yaml.FullLoader)
elif config is not None:
self._config = config
else:
raise ValueError("Could not create configuration. Must pass either location of config file or valid "
"config.")
def convert(dictionary):
return namedtuple('Config', dictionary.keys())(**dictionary)
这使我可以按如下方式拨打电话__init__:
self.input = convert(self._config["input"])
self.output = convert(self._config["output"])
self.build = convert(self._config["build_catalog"])
由于我要设置多个配置,因此我想从他的类中继承如下:
class BuildConfiguration(Configuration):
def __init__(self, config_file=None, config=None):
super().__init__(config_file, config)
self.input = convert(self._config["input"])
self.output = convert(self._config["output"])
self.build = convert(self._config["build_catalog"])
convert但是,我无法从父类访问。我也试过这个:
self.input = super().__init__.convert(self._config["input"])
这似乎也行不通。
所以问题是如何访问super().__init__子类中定义的函数?
牧羊人nacy
相关分类