MyTetra Share
Делитесь знаниями!
super
Время создания: 16.04.2017 11:25
Раздел: Python - PyQt5 - ООП
Запись: xintrea/mytetra_db_mcold/master/base/1492331106qt60twxyp8/text.html на raw.githubusercontent.com

class Base(object):
def __init__(self, parent = None):
print("Base created " + str(parent) )

class AnotherBase(object):
def __init__(self, parent = None):
print("Another Base created " + str(parent))

class ChildA(Base):
def __init__(self, parent = None):
Base.
__init__(self, 'child A')

class ChildB(AnotherBase, Base):
def __init__(self, parent = None):
super(ChildB, self).__init__('child B') # инициализация происходит по 1-ому предку, т.е. по AnotherBase

ChildA()
ChildB()

Base created child A

Another Base created child B # вызов инициализации предка Base не происходит

Также в версии Python 3 можно испльзовать упрощенную конструкцию:

class ChildB(AnotherBase, Base):
def __init__(self, parent = None):
super().__init__('child B')

Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования