Calling methods in super class constructor of subclass constructor?
Posted
by deamon
on Stack Overflow
See other posts from Stack Overflow
or by deamon
Published on 2010-05-01T08:37:46Z
Indexed on
2010/05/01
8:47 UTC
Read the original article
Hit count: 222
Calling methods in super class constructor of subclass constructor?
Passing configuration to the __init__
method which calls register
implicitely:
class Base:
def __init__(self, *verbs=("get", "post")):
self._register(verbs)
def _register(self, *verbs):
pass
class Sub(Base):
def __init__(self):
super().__init__("get", "post", "put")
Or calling register
explicitely in the subclass' __init__
method:
class Base:
def __init__(self):
self._register("get", "post")
def _register(self, *verbs):
pass
class Sub(Base):
def __init__(self):
_register("get", "post", "put")
What is better or more pythonic? Or is it only a matter of taste?
© Stack Overflow or respective owner