繁体   English   中英

如何通过继承扩展init方法

[英]How to extend init method with inheritance

我有以下代码,我试图在其中扩展BaseExporterinit方法:

from apps.ingest.platform_export import BaseExporter

class Vudu(BaseExporter):

    def __init__(self):
        BaseExporter.__init__()
        self.platform = ' Vudu'

基本上,我想要来自 BaseExporter 的所有初始化变量以及self.platform = 'Vudu'的附加变量。 我将如何正确地做到这一点?

蟒蛇 3

from apps.ingest.platform_export import BaseExporter

class Vudu(BaseExporter):
    def __init__(self):
        super().__init__()
        self.platform = ' Vudu'

蟒蛇 2

from apps.ingest.platform_export import BaseExporter

class Vudu(BaseExporter):
    def __init__(self):
        super(Vudu, self).__init__()
        self.platform = ' Vudu'

你在正确的轨道上,只是在父类中缺少自我

from apps.ingest.platform_export import BaseExporter

class Vudu(BaseExporter):

    def __init__(self):
        BaseExporter.__init__(self)
        self.platform = ' Vudu'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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