[英]How to extend init method with inheritance
I have the following code, in which I am trying to extend the init
method of BaseExporter
:我有以下代码,我试图在其中扩展
BaseExporter
的init
方法:
from apps.ingest.platform_export import BaseExporter
class Vudu(BaseExporter):
def __init__(self):
BaseExporter.__init__()
self.platform = ' Vudu'
Basically, I would like all of the init'd variables from the BaseExporter plus the additional variable of self.platform = 'Vudu'
.基本上,我想要来自 BaseExporter 的所有初始化变量以及
self.platform = 'Vudu'
的附加变量。 How would I do this correctly?我将如何正确地做到这一点?
Python 3蟒蛇 3
from apps.ingest.platform_export import BaseExporter
class Vudu(BaseExporter):
def __init__(self):
super().__init__()
self.platform = ' Vudu'
Python 2蟒蛇 2
from apps.ingest.platform_export import BaseExporter
class Vudu(BaseExporter):
def __init__(self):
super(Vudu, self).__init__()
self.platform = ' Vudu'
You were on the right track, only missing self on the parent class你在正确的轨道上,只是在父类中缺少自我
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.